用facet_labeller改facet_plot的panel名

栏目: 编程工具 · 发布时间: 6年前

内容简介:这是使用起来很简单,比如下面这个那么要改panel的名字,很容易,你只需要传入一个named vector,那么对应的名字就会被改变。比如:
I post this because I am facing the same problem: I want to change the text of the label (not the font, the face, the colour, etc: the text itself) of the leftmost panel which is automatically called Tree by ggtree. As far as I understand, and contrary to what is posted below, the theme thing of ggplot2 only allows to change the appearance of the panel header, not the text of the panel title itself So how to go about that?

这是 google group 里的问题,说的是 facet_plot 会把画树的panel叫做Tree,而他想改名,于是我就写了一个函数, facet_labeller 来回应这个问题。

使用起来很简单,比如下面这个 p2 的图,就是用 facet_plot 产生,它包含两个panel,一个叫Tree,另一个叫dot。

library(ggtree)
tr <- rtree(30) 
p <- ggtree(tr) 
d1 <- data.frame(id=tr$tip.label, location=sample(c("GZ", "HK", "CZ"), 30, replace=TRUE)) 
p1 <- p %<+% d1 + geom_tippoint(aes(color=location)) 
d2 <- data.frame(id=tr$tip.label, val=rnorm(30, sd=3)) 
p2 <- facet_plot(p1, panel="dot", data=d2, geom=geom_point,
 aes(x=val), color='firebrick') + theme_tree2()

那么要改panel的名字,很容易,你只需要传入一个named vector,那么对应的名字就会被改变。比如:

lbs <- c(Tree = "tree panel", dot = "dot panel")
facet_labeller(p2, lbs)

用facet_labeller改facet_plot的panel名

当然你可以只改变其中某一个或某一些panel,全靠你自己指定:

lbs <- c(Tree = "tree panel")
facet_labeller(p2, lbs)

用facet_labeller改facet_plot的panel名


以上所述就是小编给大家介绍的《用facet_labeller改facet_plot的panel名》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

互联网冲击

互联网冲击

杰伦•拉尼尔 (Jaron Lanier) / 李龙泉、祝朝伟 / 中信出版社 / 2014-5-1 / CNY 65.00

在《互联网冲击》一书中,关于网络技术对经济造成的影响,作者进行了卓有远见的预测。拉尼尔断言,数字网络的崛起会造成我们经济的衰退,并且摧毁中产阶级。如今,科技已经征服了一个又一个行业——从媒体到医药业,再到制造业。我们的就业形势和个人财富都将面临更加严峻的挑战。  但还有另外一种方法,能够让科技掌握我们的未来。在本书中,作者不仅展现了他的雄心壮志,而且也处处体现着他的人文关怀。拉尼尔指明了一条新信息......一起来看看 《互联网冲击》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码