小提琴剧情(geom_violin)与聚合价值 [英] Violin Plot (geom_violin) with aggregated values
问题描述
我想用汇总数据创建小提琴图。我的数据有一个类别,一个值coloumn和一个计数coloumn:
data< - data.frame(category = rep(信件[1:3],3),
值= c(1,1,1,2,2,2,3,3,3),
count = c(3,2,1 ,1,2,3,2,1,3))
如果我创建一个简单的小提琴情节它看起来像这样:
plot <-ggplot(data,aes(x = category,y = value))+ geom_violin ()
plot
http://www.ahschulz.de/pub/overflow/violin_plot.png
<这不是我想要的。解决方案是通过乘以每个类别 - 值组合的行来重塑数据帧。问题是,我的数量上升到数百万,需要数小时来绘制! : - ()
有没有解决我数据的问题?
感谢您!
您可以在计算面积时提交体重。
plot2 < - ggplot(data,aes(x = category,y = value,weight = count))+ geom_violin()
plot2
您会收到警告讯息,说明权重不会添加到一个警告讯息中,但这并没有问题,请参阅此处进行类似/相关讨论。
I would like to create violin plots with aggregated data. My data has a category, a value coloumn and a count coloumn:
data <- data.frame(category = rep(LETTERS[1:3],3),
value = c(1,1,1,2,2,2,3,3,3),
count = c(3,2,1,1,2,3,2,1,3))
If I create a simple violin plot it looks like this:
plot <- ggplot(data, aes(x = category, y = value)) + geom_violin()
plot
http://www.ahschulz.de/pub/overflow/violin_plot.png
That is not what I wanted. A solution would be to reshape the dataframe by multiplying the rows of each category-value combination. The problem is that my counts go up to millions which takes hours to be plotted! :-(
Is there a solution with my data?
Thanks in advance!
You can submit a weight when calculating the areas.
plot2 <- ggplot(data, aes(x = category, y = value, weight = count)) + geom_violin()
plot2
You will get warning messages that the weights do not add to one, but that is ok. See here for similar/related discussion.
这篇关于小提琴剧情(geom_violin)与聚合价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!