【发布时间】:2013-06-27 17:09:24
【问题描述】:
我有一个看起来像这样的数据框:
bin_with_regard_to_strand CLONE3
31 0.14750872
33 0.52735917
28 0.48559060
. .
. .
我想使用此数据框生成小提琴图,使CLONE3 中与给定值bin_with_regard_to_strand 对应的所有值都将生成一个图。
此外,我希望所有的绘图都出现在同一个图形设备中(我使用的是 R-studio,我希望所有的绘图都出现在一个绘图窗口中)。
理论上我可以这样做:
vioplot(df$CLONE3[which(df$bin_with_regard_to_strand==1)],
df$CLONE3[which(df$bin_with_regard_to_strand==2)]...)
但由于bin_with_regard_to_strand 有60 个不同的值,这似乎有点荒谬。
我尝试使用tapply:
tapply(df$CLONE3, df$bin_with_regard_to_strand,vioplot)
但这会打开 60 个不同的窗口(每个地块一个)。
或者,如果我使用add 参数:
tapply(df$CLONE3, df$bin_with_regard_to_strand,vioplot(add=TRUE))
使用来自所有值 bin_with_regard_to_strand 的数据生成一个图(以线分隔)。
有没有办法做到这一点?
【问题讨论】:
-
试试
ggplot2这里有一些例子docs.ggplot2.org/current/geom_violin.html