ggplot2 facet_wrap中带有expression()的As_labeller [英] As_labeller with expression() in ggplot2 facet_wrap

查看:144
本文介绍了ggplot2 facet_wrap中带有expression()的As_labeller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

library(ggplot2)
library(reshape)
df <- as.data.frame(matrix(runif(9),3,3))
df$factor <- letters[1:3]
df.m <- melt(df)
ggplot(df.m, aes(variable, value)) +
  geom_boxplot() +
  facet_wrap(~factor)

我想更改构面名称.根据ggplot2教程,此方法有效:

i want to change the facet names. According to the ggplot2 tutorials, this is working:

new.lab <- as_labeller(c(a="A",b="B",c="C"))
ggplot(df.m, aes(variable, value)) +
  geom_boxplot() +
  facet_wrap(~factor, labeller=new.lab)

但是,这不是:

new.lab <- as_labeller(c(a="A",b="B",c=expression(italic("C"))))
ggplot(df.m, aes(variable, value)) +
  geom_boxplot() +
  facet_wrap(~factor, labeller=new.lab)   

如何在ggplot2 2.0方面获得斜体字(或任何其他特殊符号)?

How can i get italics (or any other special symbol) in ggplot2 2.0 facets?

推荐答案

label_parsed呢?

df.m$f2 <- factor(df.m$factor, labels = c("AAA", "bold(BBB)", "italic(CCC)"))
ggplot(df.m, aes(variable, value)) + 
  geom_boxplot() + 
  facet_wrap(~f2, labeller = label_parsed) + 
  theme(text = element_text(size = 20))

这篇关于ggplot2 facet_wrap中带有expression()的As_labeller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆