本文介绍了小提琴剧情(geom_violin)与聚合价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想用汇总数据创建小提琴图。我的数据有一个类别,一个值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 plot http://www.ahschulz.de/pub/overflow/violin_plot.png ) 有没有解决我数据的问题? 感谢您!解决方案您可以在计算面积时提交体重。 plot2 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()plothttp://www.ahschulz.de/pub/overflow/violin_plot.pngThat 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()plot2You will get warning messages that the weights do not add to one, but that is ok. See here for similar/related discussion. 这篇关于小提琴剧情(geom_violin)与聚合价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-29 05:30