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

geom_cladelab: the devel version of geom_cladelabel to support aes mapping #342

Merged
merged 12 commits into from Sep 17, 2020

Conversation

xiangpin
Copy link
Member

geom_cladelab has support the original function of geom_cladelabel. But it also immits some new arguments to avoid confusion with argument of annot bar. They are barcolour or barcolor, controls the colour of bar; barsize, controls the size of barl; textcolour or textcolor, controls the colour of text; fontsize, controls the size of text; imagecolour or imagecolor control the colour of image, imagesize, controls the size of image. It also supports all the layouts.

library(ggtree)
library(ggplot2)
library(treeio)
library(patchwork)

set.seed(2015-12-21)
tree <- rtree(30)
data <- data.frame(id=c(45, 34),
                   annote=c("test clade", "another clade"),
                   image=c("7fb9bea8-e758-4986-afb2-95a2c3bf983d",
                           "0174801d-15a6-4668-bfe0-4c421fbe51e8"),
                   group=c("A", "B"),
                   offset=c(0.1, 0.1),
                   offset.text=c(0.1, 0.2))

p <- ggtree(tree) + xlim(NA, 7)

p1 <- p +
     geom_cladelab(node=45, label="test label") +
     geom_cladelab(node=34, label="another clade")

p2 <- p + geom_cladelab(data=data,
                        mapping=aes(
                             node=id,
                             label=annote,
                             color=group,
                             offset=offset,
                             offset.text=offset.text),
                        geom="shadowtext",
                        align=TRUE,
                        horizontal=FALSE,
                        angle=0
                       )
p3 <- p +
      geom_cladelabel(node=45, label="test label", align=T, angle=270, hjust='center', offset.text=.5, fontsize=8, barsize=1.5) +
      geom_cladelabel(node=34, label="another clade", align=T, angle=45)

p4 <- p + geom_cladelabel(node=34, label="another clade", align=T, geom='label', fill='lightblue')

p5 <- p1 / p3 / p4 / p2

捕获

@xiangpin
Copy link
Member Author

It also provides text, label, shadowtext, image, phylopic as the potions of geom. And text also supports emoji parse.

clade1
clade2
clade3

@GuangchuangYu GuangchuangYu merged commit 4643bf1 into YuLab-SMU:master Sep 17, 2020
@GuangchuangYu
Copy link
Member

内部函数也可以写点文档,主要是给自己看的。用#' @nord标记一下,就不会生成man文件。

@xiangpin
Copy link
Member Author

好的

@GuangchuangYu
Copy link
Member

image

把geom_cladelabel换成geom_cladelab之后,颜色就出不来了。

@xiangpin
Copy link
Member Author

xiangpin commented Nov 6, 2020

得用textcolorbarcolor才能同时上色,因为当时我想的是,有时候用户可能不想bar跟label一起上色,不同图层同时用一个color会混淆掉,所以我就加了textcolor,barcolor还有imagecolor。如果color没有在mapping里,用户想要设置颜色就需要用到这几个参数,如果用mapping了就可以用color来设置,这个会同时给bar跟label上色,如果此时只想保留label的颜色则可以用barcolor='black'来设置。

library(ggtree)
library(patchwork)
set.seed(123)
tr <- rtree(30)
                                                                                                                                                                                                        p1 <- ggtree(tr) + xlim(NA, 5.2) +
     geom_cladelab(node=41, label="chicken", parse="emoji",
                   fontsize=6, align=TRUE, textcolor="firebrick", barcolor="firebrick") +
     geom_cladelab(node=53, label="duck", parse="emoji",
                   fontsize=6, align=TRUE, textcolor="steelblue", barcolor="steelblue") +
     geom_cladelab(node=48, label="family", parse="emoji",
                   fontsize=6, align=TRUE, textcolor="darkkhaki", barcolor="darkkhaki")

df <- data.frame(node=c(41, 53, 48),
                 labels=c("chicken", "duck", "family"))

p2 <- ggtree(tr) + xlim(NA, 5.2) +
      geom_cladelab(data=df,
                    mapping=aes(node=node, label=labels, color=labels),
                    parse="emoji",
                    fontsize=6,
                    align="TRUE"
                    ) +
      scale_color_manual(values=c("firebrick", "steelblue", "darkkhaki"),
                         guide="none")

p3 <- ggtree(tr) + xlim(NA, 5.2) +
      geom_cladelab(data=df,
                    mapping=aes(node=node, label=labels, color=labels),
                    parse="emoji",
                    fontsize=6,
                    align="TRUE",
                    barcolor="black") +
      scale_color_manual(values=c("firebrick", "steelblue", "darkkhaki"),
                         guide="none")

p <- p1 / p2 / p3
p

test_clade

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

Successfully merging this pull request may close these issues.

None yet

2 participants