如何将上标添加到构面标签

问题描述 投票:2回答:1

我试图绘制三个变量,并希望轴标签中的单位,但无法找到一种方法来标记它们与上标的方面。

我尝试过as_labellerlabel_bquoteexpression / paste并更改原始数据。

p <- ggplot(data = LST, aes(x = Date, y = Measurements)) + 
geom_point((aes(color = parameter)))

p + facet_grid(parameter ~ ., scales = "free_y", 
switch="y",labeller=as_labeller(DO~(mg~L^{-1}), Temperature~(°C), Light~ 
(µmol~m^{-2}~s^{-1}))) + 
            theme_bw()+ theme(strip.background = element_blank(), 
legend.title = element_blank(), strip.placement = "outside", 
panel.grid.minor = element_blank()) + 
          scale_x_datetime()+ ylab(NULL) +ggtitle("Spring 2018") + 
scale_colour_manual(values=c('royalblue1', 'springgreen4', 'darkblue')) +
          theme(legend.position="none")+ 
theme(strip.text=element_text(size=10))

我尝试的所有内容都标记所有方面相同或不放置上标。我在ggplot2很新,所以我不确定我的尝试是否会有所帮助。

r ggplot2 label facet
1个回答
1
投票

你想要labeller = label_parsed。这是一个简单的例子

mt = mtcars

mt$facets = factor(mt$cyl, labels = c(
    "DO~(mg~L^{-1})", 
    "Temperature~('°C')", 
    "Light~(µmol~m^{-2}~s^{-1})"))

ggplot(mt, aes(mpg,cyl)) +
  geom_point() +
  facet_grid(~facets, labeller = label_parsed)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.