当我使用一个物种的小提琴情节(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")