how is pwidth meant to be used?

161 views
Skip to first unread message

Yasir Kusay

unread,
May 19, 2021, 12:21:21 AM5/19/21
to ggtree
Hi,

I have the below code:

library(ggtree)
library(tidyverse)
library(ggtreeExtra)

tree <- read.tree(text='(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);')


Accession1 <- c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M')
Column1 <- c('10', '20', '30', '40', '50', '60', '70', '80', '90', '100', '110', '120', '130')

dd = data.frame(Accession1, Column1)
print(dd)

p <- ggtree(tree) + ylim(-1, NA) + theme_tree2() 

p <- p %<+% dd

dd$Column1 <- as.numeric(dd$Column1) 

col = "NULL"
to_map = "Column1"
assign(col, dd[[to_map]])









Now the next few lines of code produce exactly the same image. 
-> p + geom_tiplab() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 0.4, offset = 0.03) + new_scale_fill() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 10, offset = 0.03) 

-> p + geom_tiplab() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 0.4, offset = 0.03) + new_scale_fill() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 0.01, offset = 0.03) 

-> p + geom_tiplab() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 0.9, offset = 0.03) + new_scale_fill() + geom_fruit(geom = geom_tile, mapping = aes(fill = Accession1), pwidth = 0.01, offset = 0.03) 

Each of the above adjusts pwidth, yet it produces the exact same plot. What is pwith meant to do exactly? How to I adjust it such that it can change the plot.

xush...@gmail.com

unread,
May 19, 2021, 6:04:17 AM5/19/21
to ggtree

This is because the external layer is a single column geom_tile, and the x value of geom_tile is a point, not a range.
The point multiply by the pwidth of the x range of the tree will return a constant.
But you can use the width of geom_tile to adjust the width of the single column geom_tile layer.

library(ggtree)
library(tidyverse)
library(ggtreeExtra)
library(ggnewscale)

tree <- read.tree(text='(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);')

Accession1 <- c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M')
Column1 <- c('10', '20', '30', '40', '50', '60', '70', '80', '90', '100', '110', '120', '130')

dd = data.frame(Accession1, Column1)

p <- ggtree(tree) + ylim(-1, NA)

fig <- p +
       geom_tiplab() +
       geom_fruit(
           geom = geom_tile,
           mapping = aes(fill = Accession1),
           width = 2,
           offset = 0.1
       ) +
       new_scale_fill() +
       geom_fruit(
           geom = geom_tile,
           mapping = aes(fill = Accession1),
           width = 4,
           offset = 0.08
       )

Reply all
Reply to author
Forward
0 new messages