How can I have a Greek symbol within one of my facet labels?

与世无争的帅哥 提交于 2019-12-02 00:57:07
Djork

Here is a trick that uses labeller=label_parsed.

First, define labels for df$genes that uses the expression to be parsed:

df$genes <- factor(df$genes, levels = c("BA","MLL","pos","neg","PMLalpha+"),
 ordered = TRUE, labels=c("BA","MLL","pos","neg",expression(paste("PML", alpha,"+"))))

Then use labeller=label_parsed in facet_wrap:

ggplot(df,aes(x=genes, y=value)) + geom_boxplot()+ 
  facet_wrap(~genes, ncol = 5, scales = "free_x", labeller = label_parsed)

As you can see this messes with the x-axis labels, but you can fix it in scale_x_discrete as follows:

ggplot(df,aes(x=genes, y=value)) + geom_boxplot()+ 
  facet_wrap(~genes, ncol = 5, scales = "free_x", labeller = label_parsed) +
  scale_x_discrete(name="",
               breaks = c("BA","MLL","pos","neg","paste(\"PML\", alpha, \"+\")"),
               labels = c("BA","MLL","pos","neg", expression(paste("PML", alpha,"+"))))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!