簡體   English   中英

從 ggtree 圖中刪除“a”

[英]Remove the 'a' from ggtree figure

給定一棵樹,其提示標簽按組着色,例如:

 library(ggplot2)
 library(ggtree)
 nwk <- system.file("extdata", "sample.nwk", package="treeio")
 tree <- read.tree(nwk)
 meta = data.frame(label = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"),
              group = c(rep("mammal", 5), rep("insect", 5), rep("bird", 3)))

 p = ggtree(tree) %<+% meta +
     geom_tiplab(aes(color = group))

圖例將包含a而不是所需的正方形。 ggplot2文檔說使用“override.aes”來覆蓋這種行為:

p + guides(color = guide_legend(override.aes = list(size = 4,
                                             label = "",
                                             shape = 15)))

這不起作用。 最重要的是,我可以更改大小、顏色、刪除a但最重要的是我不能使用不同的形狀(在本例中為正方形)。

較新版本的 ggplot2 具有key_glyph選項,但是在使用geom_tiplab時這也沒有效果。

另一個奇怪的行為是,當使用geom_tipppoint時,覆蓋圖例有效。 值得注意的是,上述策略以前可以刪除a ,但是在最新的 R/ggplot2/ggtree 中,上述策略不起作用。 這與ggtree的最新版本有關,與舊版本無關。

關於如何覆蓋geom_tiplab()圖例形狀的任何建議?

我的環境:

R version 4.1.2 (2021-11-01)
ggplot2 version 3.3.5
ggtree version 3.2.1
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 20

在此處輸入圖像描述

["

library(ggplot2)
library(ggtree)
#> Registered S3 method overwritten by 'ggtree':
#>   method      from 
#>   identify.gg ggfun
#> ggtree v3.0.4  For help: https://yulab-smu.top/treedata-book/
#> 
#> If you use ggtree in published research, please cite the most appropriate paper(s):
#> 
#> 1. Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics, 2020, 69:e96. doi:10.1002/cpbi.96
#> 2. Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
#> 3. Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
meta = data.frame(label = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"),
                  group = c(rep("mammal", 5), rep("insect", 5), rep("bird", 3)))

ggtree(tree) %<+% meta +
  geom_tiplab(aes(color = group), show.legend = FALSE) +
  geom_polygon(aes(fill = group, x = 0, y = 0)) +
  scale_fill_discrete(na.translate = F)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM