我想用 ggplot 要创建一个小提琴图,其中小提琴的宽度不是由密度函数控制的,而是直接表示相关元素的数量。
ggplot
我想这可以通过设置 geom_violin(stat="identity")
geom_violin(stat="identity")
> ggplot(allData, aes(x = tool, y = length)) + geom_violin(stat="identity") Warning: Ignoring unknown parameters: trim, scale Error in eval(substitute(list(...)), `_data`, parent.frame()) : object 'violinwidth' not found
正在尝试添加 aes(violinwidth=0.2*count) ,作为 this answer 建议,给予
aes(violinwidth=0.2*count)
> ggplot(allData, aes(x = tool, y = length)) + geom_violin(stat="identity", aes(violinwidth=0.2*count)) Warning: Ignoring unknown parameters: trim, scale Warning: Ignoring unknown aesthetics: violinwidth Error in FUN(X[[i]], ...) : object 'count' not found
violinwidth 对于一个常数,这使得小提琴只是矩形。我该怎么解决?
violinwidth
当我用一些样本数据运行这个程序时,它生成的绘图可以在 stat 和 violinwidth . 是你的吗 count 一列 allData ?
stat
count
allData
library(ggplot2) dt <- data.frame(category = rep(letters[1:2], each = 10), response = runif(20), count = rpois(20, 5)) ggplot(dt, aes(x = category, y = response)) + geom_violin() ggplot(dt, aes(x = category, y = response)) + geom_violin(stat = "identity", aes(violinwidth = 0.1*count))