The dataset I used can be downloaded here: https://dropfile.to/aEWZ5U2.
I wanted to make a violin plot with a boxplot in it.
I used the following code with the dataset:
for (c in c('age','educ','hours')){
print(ggplot(data, aes_string(y=c))+
geom_violin(aes(x=c),trim=T, fill='grey', draw_quantiles = c(0.25,0.5,0.75)) +
geom_boxplot(aes(x=c),width=.1, fill='skyblue', outlier.size = 0.7, outlier.color = 'red'))
}
This makes 3 plots. There first one looks as expected, but the second and third one not because the medians do not overlap (see picture), although in my understanding they should. I first thought that this might be related to missing values (because there are a lot in this dataset. But if I use
na.omit(data)
instead of data, there also the problem with different medians. In my understanding violin-plots should display 0.25, 0.5 and 0.75 quartiles just like boxplots. What is wrong in my code or maybe is my understanding of violing vs boxplots incorrect?