Violin Plot (geom_violin) with aggregated values

后端 未结 2 1262
自闭症患者
自闭症患者 2021-01-13 10:59

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(LE         


        
相关标签:
2条回答
  • 2021-01-13 11:06

    Using stat="identity" and specifying a violinwidth aesthetic appears to work,although I had to put in a fudge factor:

    ggplot(data, aes(x = category, y = value)) + 
       geom_violin(stat="identity",aes(violinwidth=0.2*count))
    
    0 讨论(0)
  • 2021-01-13 11:08

    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.

    enter image description here

    0 讨论(0)
提交回复
热议问题