专栏名称: EasyCharts
EasyCharts,易图表,我们将定期推送各种数据可视化与分析教程,包括Excel(Power BI)、Origin、Sigmaplot、GraphPad、R、Python、Matlab、Tableau、D3.js等。
目录
相关文章推荐
前端大全  ·  历时 5 ... ·  昨天  
前端早读课  ·  工作阶段性迷茫,怎么办 ·  14 小时前  
吉林市场监管  ·  3·15优化消费环境 市场监管在行动 ⑦|辉南县 ·  昨天  
吉林市场监管  ·  3·15优化消费环境 市场监管在行动 ⑦|辉南县 ·  昨天  
青云说说  ·  如何定义好酒? ·  2 天前  
青云说说  ·  如何定义好酒? ·  2 天前  
51好读  ›  专栏  ›  EasyCharts

ggjoy 和ggtree:双剑合璧,惊艳无比

EasyCharts  · 公众号  · 前端  · 2017-08-04 07:00

正文

之前介绍了《 joyplot:一种波涛汹涌,哦不对,是山峰叠峦的可视化方式 》,最近有人问怎么和ggtree搞基,像这样的问题,大家应该不陌生,因为我在《 align genomic features with phylogenetic tree 》一文中已经直播了和ggbio的搞基过程。

我在《 how to bug author 》一文中,就强调了在社区里问问题的重要性,想要ggjoy和ggtree搞基的问题,就没有直接问我,而是在同性交友网站stackoverflow上问,在我回答之前,就已经有非常好的解答贴出来了,这就是社区的好处!公开交流比私下邮件好多了。


问题

Is it possible to add a joyplot as a panel to a plot that includes a ggtree, as shown in these examples? Examples of joyplots are here.

  • https://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/

  • https://katherinemwood.github.io/post/joy/

I realize that I could manually put the species labels for the joyplot in the same order as the tree tip labels, but I am looking for an automatic solution. I would like to associate the joyplot rows with the tips of the trees automatically, akin to how the boxplot data are associated with the tip labels.

I think that Guangchuang Yu’s examples at the above link provide suitable data:

require(ggtree)
require(ggstance)# generate tree

tr 30)# create simple ggtree object with tip labels
p 0.02)
# Generate categorical data for each "species"
d1 "GZ", "HK", "CZ"), 30, replace=TRUE))
#Plot the categorical data as colored points on the tree tips

p1 # Generate distribution of points for each species

d4 = data.frame(id=rep(tr$tip.label, each=20),            val=as.vector(sapply(1:30, function(i)                            rnorm(20, mean=i)))            )               # Create panel with boxplot of the d4 data
p4 "Boxplot", data=d4, geom_boxploth,        mapping = aes(x=val, group=label, color=location))           plot(p4)

This produces the plot below:

Is it possible to create a joyplot in place of the boxplot?

Here is code for a quick joyplot of the demo dataset d4 above:

require(ggjoy)

ggplot(d4, aes(x = val, y = id)) + 
geom_joy(scale = 2






请到「今天看啥」查看全文