I am trying to add a scale to an unrooted tree with geom_treescale, but when I use it, the tree completely collapses and I am not able to set anything that fix it. Anybody has any idea on how to do it ?

google group里的问题,说他加geom_treescale之后,树被压缩了,由于他没有给出可重复性的例子,所以我们并不知道情况到底有多么糟糕,但这种情况是可能发生的,因为加treescale这种东西,默认情况下geom_treescale会自己去计算该加多大的scale bar,该放在什么位置上,而这种默认情况是基于rectangular布局来的,在假设的情况下,都不可能尽善尽美,假设不成立的情况下当然有可能搞得很差。

但这不要紧,因为要放在什么位置,放多大的legend,scale bar和text的相对位置,线条和文字的大小、颜色、字体等都是可以由用户指定的。所以啊,你可以通过自己指定,调整到自己满意为止。因为进化树一般我们不会打印出坐标轴,如果你对坐标轴的位置毫无概念,你可以使用+ theme_grey()把坐标轴打印出来,这样对于位置就非常清楚了。最后出图的时候,你可以把+ theme_grey()去掉,这样就又变成了没有坐标轴的空白背景。

library(ggtree)
set.seed(20180224)
x = rtree(30)
ggtree(x, layout='unrooted') -> p
p + ggplot2::theme_grey() + 
	geom_treescale(x=7, y=-5.5, offset=.1)