ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

geom_treescale and layout="fan"

Open mdhall272 opened this issue 6 years ago • 4 comments
trafficstars

geom_treescale interacts oddly with the fan layout:

  • If you give x and y they are actually interpreted as r and theta (polar coordinates)
  • The units for y are are not degrees, radians or anything else standard, but based on the number of tips in the tree (i.e. 1 point of y is 360/n degrees where the tree has n tips)
  • The scale line rotates as y changes. The above two points are manageable, but this means tinkering with a vector graphics package is basically essential if you want to place the scale

MWE:


library(ape)
library(ggtree)

a.tree <- rtree(100)

# small and large x values scale the tree
ggtree(a.tree, layout='fan') + geom_treescale(x = -50)
ggtree(a.tree, layout='fan') + geom_treescale(x = 50)
# y values rotate the line
ggtree(a.tree, layout='fan') + geom_treescale(x = 7, y = 15)

mdhall272 avatar Jun 19 '19 10:06 mdhall272

I was going to open the same issue for layout = "circular". It would be great to be able to position the scale in cartesian coordinates and be able to the bar horizontal.

Bisaloo avatar Jun 25 '19 15:06 Bisaloo

it would be OK if y = 0.

GuangchuangYu avatar Jun 26 '19 09:06 GuangchuangYu

If one is happy to have the scale to the right of the plot, sure. I'd like it below.

mdhall272 avatar Jun 26 '19 09:06 mdhall272

coord_radar seems to be a solution to this.

I don't have time to explore the details and this feature is not in high priority.

If you can work it out, PR is welcome.

GuangchuangYu avatar Jun 26 '19 10:06 GuangchuangYu