当我对一个物种(Pan)使用小提琴图时,我的代码如下所示:
my.vioplot(getFemales(toPlotAggregated,"Pan"),getMales(toPlotAggregated,"Pan"),col=c("red","blue"),names=c("females","males"))
它生成单个图,女性为红色,男性为蓝色。但是,我想遍历我拥有的所有物种,这就是这个变量中的内容:
levels(factor(toPlotAggregated$species))
vioplot 接受任意数量的数据集,因此由于每个物种都需要雌性和雄性,因此我需要生成 2*(物种数)数据集以传递给 vioplot。因此,对于两个物种,它将类似于:
my.vioplot(SPECIES1_females,SPECIES1_males,SPECIES2_females,SPECIES2_males,...)
我试过用“by”和“apply”来做这件事,但到目前为止还没有成功。
编辑:
我的数据示例:
dput(tail(toPlotAggregated))
structure(list(name = c("Taweh", "Bwambale", "Vincent", "Bosco",
"Clint", "Buschi"), species = c("Pan", "Pan", "Pan", "Pan", "Pan",
"Pongo"), fullSpecies = c("Pan_troglodytes_ellioti", "Pan_troglodytes_schweinfurthii",
"Pan_troglodytes_schweinfurthii", "Pan_troglodytes_verus", "Pan_troglodytes_verus",
"Pongo_abelii"), sex = c("M", "M", "M", "M", "M", "M"), counts = c(52.989924558446,
85.2531017739286, 118.811705035969, 65.8304927403788, 48.0129119517474,
63.7682831797004)), .Names = c("name", "species", "fullSpecies",
"sex", "counts"), row.names = 54:59, class = "data.frame")