【发布时间】:2018-11-22 17:14:01
【问题描述】:
又一个贴标机问题...我正在努力在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])
))
这按预期工作
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
facet_wrap(~ Species, labeller = var.lab1) +
geom_point()
这不起作用(贴标机无效)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) +
facet_wrap(~ Species, labeller = var.lab2) +
geom_point()
这行得通
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()
但ggplot2 不满意“警告消息:标注器 API 已更新。现在不推荐使用带有变量和值参数的标注器。请参阅标注器文档。”
【问题讨论】:
-
我会在这里参考我的答案:stackoverflow.com/a/58307679/3392714