Yet another labeller question... I am struggling using math expressions in labellers with ggplot2
> 3
library(ggplot2)
var.lab1 = as_labeller(c(
"setosa" = "se",
"versicolor" = "ve",
"virginica" = "vi"
))
var.lab2 = as_labeller(c(
"setosa" = bquote("Spp"[set]),
"versicolor" = bquote("Spp"[ver]),
"virginica" = bquote("Spp"[vir])
))
This works as expected
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
facet_wrap(~ Species, labeller = var.lab1) +
geom_point()
This doesn't work (the labeller has no effect)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
facet_wrap(~ Species, labeller = var.lab2) +
geom_point()
And this works
var.lab3 = c(
"setosa" = bquote("Spp"[set]),
"versicolor" = bquote("Spp"[ver]),
"virginica" = bquote("Spp"[vir])
)
vlabeller <- function (variable, value) {
return(var.lab3[value])
}
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
facet_wrap(~ Species, labeller = vlabeller) +
geom_point()
But ggplot2
is unhappy "Warning message: The labeller API has been updated. Labellers taking variable and value arguments are now deprecated. See labellers documentation."