我有下面的图,但我想用适当的delta格式表示同位素名称。以前,我在轴标签中使用了以下代码:
p + labs(x = expression(paste(paste(delta^2,"H"))))
但在我的下图的facet_grid标签编辑器中不起作用:
p + facet_grid(sex ~ iso,
scale = "free_x",
labeller = labeller(iso = c("d2H" = expression(paste(paste(delta^2,"H"))),
"d13C" = expression(paste(paste(delta^13,"C"))),
"d15N" = expression(paste(paste(delta^15,"N")))),
sex = c("F" = "female",
"M" = "male")))
如何更改构面中的名称?
答案 0 :(得分:1)
一种方法是将label_parsed
用作labeller
。但要做到这一点,必须将构面因子的标签更改为要显示的内容。
我将以内置数据集iris
为例。
library(ggplot2)
iris$Species <- factor(iris$Species,
labels = c(bquote(delta^2*H),
bquote(delta^13*C),
bquote(delta^15*N)))
p <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Width)) +
geom_point()
p + facet_grid(~ Species,
scale = "free_x",
labeller = label_parsed
)