1

So im trying to make some different Boxplots,

Completely normal boxplot

I can't figure out how to create the boxplot without the lower and upper quantile, which essentially would be the outliers and the median connected by the whiskers. So something which would look like this

My attempt

But i need a total connection with a vertical line between the whisker?

what i did for the second plot in R was the following

boxplot(mpg~cyl,data=mtcars, main="Car Milage Data", xlab="Number of Cylinders", 
        ylab="Miles Per Gallon",col="white",frame=F,medcol = "black", boxlty =0, 
        whisklty = 1, staplelwd = 1,boxwex=0.4)

Many Thanks.

kath
  • 7,624
  • 17
  • 32
RAHenriksen
  • 143
  • 2
  • 12
  • I know that statistically its really stupid, but my professor wants to join this plot with a scatterplot of the pure dataset, so in reality we only need to see the whiskers and the median. And to join the plot i would just use stripchart. – RAHenriksen Apr 19 '18 at 15:33
  • Ok just checking ;) so, your end goal is something like this https://i.stack.imgur.com/h5Kpz.png, but without the box? – Ale Apr 19 '18 at 15:37
  • That is correct :-) – RAHenriksen Apr 19 '18 at 15:39
  • why not just overlay the scatter plot data with the boxplot? I don't understand how removing the quantiles helps with what you are describing you are trying to do: combine two plots. – Puddlebunk Apr 19 '18 at 15:40
  • I dont need the information the lower and upper quantiles are giving, so its purely visually. As the the overlayed scatter plot might not contain many points, so its was just to get a easier view of the points :-) – RAHenriksen Apr 19 '18 at 15:43
  • Well check the package beanplot, hope it helps – Ale Apr 19 '18 at 15:43
  • would doing a scatter plot with error bars be more in line what what you are going for then? – Puddlebunk Apr 19 '18 at 15:43
  • Okay thanks Ale, i suspected that might be the case, as it then really wouldn't be a boxplot. But thanks anyways. – RAHenriksen Apr 19 '18 at 15:44
  • I dont think a scatterplot with error bars would help in this instance, since what we're plotting with the boxplots are some processed data, and then i would like to overlay with the original data. But i can look into it. – RAHenriksen Apr 19 '18 at 15:50

1 Answers1

0

Here is a way to get what you are looking for using a scatter plot and error bars:

    library(tidyverse)

        data_summary <- data %>%
          group_by(grouping_var) %>%
          summarize(median = median(quant_var),
                max = max(quant_var),
                min = min(quant_var))

    ggplot(data_summary, aes(x = grouping_var,
                             y = median)) +
      geom_point() +
      geom_errorbar(aes(ymin = min,
                        ymax = max))

Then if you need to overlay your old data you can just add a new geom like so:

    ggplot(data_summary, aes(x = grouping_var,
                             y = median)) +
      geom_point() +
      geom_errorbar(aes(ymin = min,
                        ymax = max)) +
      geom_point(data = data, aes(x = grouping_var,
                                  y = quant_var))
Puddlebunk
  • 493
  • 3
  • 10