0

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?

Violin Plot

aosmith
  • 34,856
  • 9
  • 84
  • 118
Jaynes01
  • 521
  • 1
  • 5
  • 20
  • 1
    Possible duplicate of [Differing quantiles: Boxplot vs. Violinplot](https://stackoverflow.com/questions/36033341/differing-quantiles-boxplot-vs-violinplot) – Z.Lin Sep 25 '17 at 00:52
  • @Z.Lin: That might indeed be the case. I do not expect that there is a 'solution' for that problem then. I think I should decide to leave out one of the methods for showing quartiles... I think I should delete this post then, shouldn't I? – Jaynes01 Sep 25 '17 at 05:51

0 Answers0