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来回应这个问题。


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)


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