I am creating violin plot using ggplot in R. I want to create violin plot showing different number count in each plot like this.
I used this code to create plot like this.
data<-read.csv("Clinical violion file.csv")
mat <- reshape2::melt(data.frame(data), id.vars = NULL)
pp <- ggplot(mat, aes(x = variable, y = value)) + geom_violin(scale="width",adjust = 1,width = 0.5,aes(color=factor(variable)))+ geom_point()
pp
I have got plot like this.
But I don't know how to add point showing different number count in each plot. Here is header of my file.
I solved this issue by doing this.
library(ggbeeswarm)
pp <- ggplot(mat, aes(x = variable, y = value)) + geom_violin(scale="width",adjust = 1,width = 0.5,aes(color=factor(variable)))+geom_quasirandom(aes(color=factor(variable)),groupOnX=FALSE)
ggbeeswarm::geom_quasirandom()
vsgeom_point()
to get jittering to enable showing the cases where points overlap. You can usegeom_text()
to position total count of observations in each group on the plot or modify the factor labels to add them there. – hrbrmstr