首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在facet_wrap中添加ggplot2下标和符号

在facet_wrap中添加ggplot2下标和符号
EN

Stack Overflow用户
提问于 2021-08-25 16:16:34
回答 1查看 249关注 0票数 0

随着时间的推移,我试图创建一些天气状况的2x2面图,并且在为一些面标题添加学位符号和上标时遇到了困难。

代码语言:javascript
运行
复制
weatherPLOT = data.frame(weather = rep(c("Soil Temperature (C)", 
                                        "Snow Depth (m)", 
                                        "Air Temperature (C)", 
                                        "Discharge (m3/sec)"), each = 366),
                           day = 1:366,
                           mean = 3, # Obvious place holders,
                           Lo95 = 2, # Are actual numbers in real code
                           Hi95 = 4)

ggplot(aes(y = mean, x = day), data = weatherPLOT) + 
  geom_ribbon(aes(ymin = Lo95, ymax = Hi95), alpha = 0.25) +
  geom_path(size = 1) + 
  theme(axis.title.y = element_blank()) + xlab("Julian Day") +
  facet_wrap( ~ weather, nrow = 2, ncol = 2, scales = "free")

我知道诀窍是在facet_wrap内部使用标签器,但我不能让它工作-我只是想在(C)之前添加一个度符号,并使3 in (m3/秒)被迷信。

EN

回答 1

Stack Overflow用户

发布于 2021-08-25 17:03:39

另一种方式是:

代码语言:javascript
运行
复制
weatherPLOT %>%
  mutate(weather = factor(weather,
                          labels = c(bquote('Air Temperature'*degree*C),
                                     "Discharge~(m^{3}/sec)",
                                     "Snow~Depth~(m)",
                                     bquote('Soil Temperature'*degree*C)))) %>% 
  ggplot(aes(y = mean, x = day)) + 
  geom_ribbon(aes(ymin = Lo95, ymax = Hi95), alpha = 0.25) +
  geom_path(size = 1) + 
  theme(axis.title.y = element_blank()) + xlab("Julian Day") +
  facet_wrap( ~ weather, nrow = 2, ncol = 2, scales = "free", labeller =  label_parsed)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68926485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档