小编LCM*_*LCM的帖子

与ggtree ggjoy facet

是否可以将一个joyplot作为面板添加到包含ggtree的图中,如这些示例所示?这里有joyplots的例子.

我意识到我可以按照与树尖标签相同的顺序手动设置joyplot的物种标签,但我正在寻找一种自动解决方案.我想自动将joyplot行与树的提示相关联,类似于boxplot数据与tip标签的关联方式.

我认为Yuchuang Yu在上面链接的例子提供了合适的数据:

require(ggtree)
require(ggstance)

# generate tree
tr <- rtree(30)

# create simple ggtree object with tip labels
p <- ggtree(tr) + geom_tiplab(offset = 0.02)

# Generate categorical data for each "species"
d1 <- data.frame(id=tr$tip.label, location=sample(c("GZ", "HK", "CZ"), 30, replace=TRUE))

#Plot the categorical data as colored points on the tree tips
p1 <- p %<+% d1 + geom_tippoint(aes(color=location))

# 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))) …
Run Code Online (Sandbox Code Playgroud)

r data-visualization ggplot2 ggtree ggridges

12
推荐指数
1
解决办法
2393
查看次数

将列拆分为两个具有相同列名的新列

我想将每列中用逗号分隔的值对分成新数据框中的两个相邻列,并为两个新列中的每一列分配相同的列名.

也就是说,我想转换这个:

A   B   C   D   E 
1,1 0,1 1,1 1,1 1,1 
1,1 1,1 1,1 1,1 1,1
0,1 0,1 0,1 0,1 0,1 
Run Code Online (Sandbox Code Playgroud)

对此:

A  A  B  B  C  C  D  D  E  E
1  1  0  1  1  1  1  1  1  1
1  1  1  1  1  1  1  1  1  1
0  1  0  1  0  1  0  1  0  1
Run Code Online (Sandbox Code Playgroud)

如果数据框名称不能具有完全重复,则A_1和A_2 ......等等应该没问题.或者,将数据框的第一行中的名称替换为标题也可以.

我的实际数据集是大约200列~13,000行,所以我需要一种自动方法来分割列并将名称分配给数据帧的第二个版本.

r

1
推荐指数
1
解决办法
126
查看次数

标签 统计

r ×2

data-visualization ×1

ggplot2 ×1

ggridges ×1

ggtree ×1