Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing negative values after adjust pwidth parameter #23

Open
Microbion opened this issue Sep 8, 2022 · 9 comments
Open

Missing negative values after adjust pwidth parameter #23

Microbion opened this issue Sep 8, 2022 · 9 comments

Comments

@Microbion
Copy link

I adjust the pwidth to control the width of the barplot layer, as #2 told. But negative values will be missing when pwidth is higher.

ggtree(tree, layout = "radial", ladderize = FALSE, branch.length = "none", aes(color = group)) +
xlim(-10, NA) +
scale_color_viridis_d() +
ggnewscale::new_scale_color() +
geom_fruit(data = deseq_res, geom = geom_bar, stat = "identity", orientation = "y", pwidth = 0.25, offset = 0.2,
           mapping = aes(x = log2FoldChange, y = row, color = color))

And it's going well, like this:
image
But if I ajust pwidth to 5 (or smaller than 5), I get Warning message "“Removed 355 rows containing missing values (position_stackx).”", and lose lots of negative values.
image
Is it suite for my situation?

@xiangpin
Copy link
Member

xiangpin commented Sep 9, 2022

How about re-installing the github version by remotes::install_github('YuLab-SMU/ggtreeExtra').

> library(ggtreeExtra)
ggtreeExtra v1.7.0.990 For help:
https://yulab-smu.top/treedata-book/

If you use the ggtree package suite in published research, please cite
the appropriate paper(s):

S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L
Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact
visualization of richly annotated phylogenetic data. Molecular Biology
and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
> set.seed(1024)
> tr <- rtree(100)
> dd = data.frame(id=tr$tip.label, value=rnorm(100))
> dd %<>% dplyr::mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'))
> p <- ggtree(tr, layout="circular")
> p + geom_fruit(data = dd, geom=geom_col, mapping=aes(x=value, fill=group, y=id), offset=.2, pwidth=.2, axis.params=list(axis='x', text.size=2, vjust=1), grid.params=list())

xx

PS: I think you can use fill=color instead of color = color in aes of geom_fruit, then you remove the ggnewscale::new_scale_color()

@Microbion
Copy link
Author

Microbion commented Sep 9, 2022

Thanks for your reply @xiangpin. My checked package version, it's 1.7.0.998 now. And tested your code, everything went ok. But when I tried my data, I got the same warning again. I guess it may be caused by my value's distribution. The absolute values of negative values are higher than positive values, and not the random distribution.
Here's the density plot of values which I used in bar plot. But I have no idea about why it comes.
image

How about re-installing the github version by remotes::install_github('YuLab-SMU/ggtreeExtra').

> library(ggtreeExtra)
ggtreeExtra v1.7.0.990 For help:
https://yulab-smu.top/treedata-book/

If you use the ggtree package suite in published research, please cite
the appropriate paper(s):

S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L
Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact
visualization of richly annotated phylogenetic data. Molecular Biology
and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166
> set.seed(1024)
> tr <- rtree(100)
> dd = data.frame(id=tr$tip.label, value=rnorm(100))
> dd %<>% dplyr::mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'))
> p <- ggtree(tr, layout="circular")
> p + geom_fruit(data = dd, geom=geom_col, mapping=aes(x=value, fill=group, y=id), offset=.2, pwidth=.2, axis.params=list(axis='x', text.size=2, vjust=1), grid.params=list())

xx

PS: I think you can use fill=color instead of color = color in aes of geom_fruit, then you remove the ggnewscale::new_scale_color()

@xiangpin
Copy link
Member

xiangpin commented Sep 9, 2022

Sorry, I can not debug, because I can not reproduce the issue even though I built the same dataset you told. Would you mind sharing your data via email if you do not want to make it public?

@Microbion
Copy link
Author

I reproduced the issue with your example with adding xlim(-2, NA) and rising pwidth to 0.5. I guess that xlim function acts on the whole layer and geom_fruit seems not treat it well, or do you have any advise like ggnew_scale package? Here's my code below:

set.seed(1024)
tr <- rtree(100)
dd = data.frame(id=tr$tip.label, value=rnorm(100)) %>%
mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'), 
)
p <- ggtree(tr, layout="circular") + xlim(-2, NA)
p +
geom_fruit(data = dd, geom = geom_col, mapping=aes(x=value, fill=group, y=id), offset = .2, pwidth=.5)

And the warning showed again
image
PS: Sorry for forgetting festivals in the last post. Wish you and your family a happy Mid-Autumn Festival and Mr. Yu a happy Teacher's Day too.

@Microbion
Copy link
Author

So is it the same question? #17

@xiangpin
Copy link
Member

Yes, This issue was caused by the xlim . You can use geom_blank(aes(x=-2)) to replace xlim.

> library(dplyr)
> library(ggplot2)
> library(ggtreeExtra)
> library(ggtree)
> set.seed(1024)
> tr <- rtree(100)
> dd = data.frame(id=tr$tip.label, value=rnorm(100)) %>% mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'))
> p <- ggtree(tr, layout="circular")
> p + geom_blank(aes(x=-2)) + geom_fruit(data = dd, geom = geom_col, mapping=aes(x=value, fill=group, y=id), offset = .2, pwidth=.5)

@Microbion
Copy link
Author

Microbion commented Sep 14, 2022

Yes, that's what my want indeed. Thanks very much.

Yes, This issue was caused by the xlim . You can use geom_blank(aes(x=-2)) to replace xlim.

> library(dplyr)
> library(ggplot2)
> library(ggtreeExtra)
> library(ggtree)
> set.seed(1024)
> tr <- rtree(100)
> dd = data.frame(id=tr$tip.label, value=rnorm(100)) %>% mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'))
> p <- ggtree(tr, layout="circular")
> p + geom_blank(aes(x=-2)) + geom_fruit(data = dd, geom = geom_col, mapping=aes(x=value, fill=group, y=id), offset = .2, pwidth=.5)

@GuangchuangYu
Copy link
Member

@xiangpin I am wondering whether the xlim_tree is compatible with this case?

@xiangpin
Copy link
Member

Yes, the xlim_tree can also solve the problem.

> library(dplyr)
> library(ggplot2)
> library(ggtreeExtra)
> library(ggtree)
> set.seed(1024)
> tr <- rtree(100)
> dd = data.frame(id=tr$tip.label, value=rnorm(100)) %>% mutate(group=dplyr::case_when(value < 0 ~ "A", TRUE ~ 'B'))
> p <- ggtree(tr, layout="circular")
> p + geom_fruit(data = dd, geom = geom_col, mapping=aes(x=value, fill=group, y=id), offset = .2, pwidth=.5) + xlim_tree(-10)

xx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants