1
votes

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.

1
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
Ok just checking ;) so, your end goal is something like this i.stack.imgur.com/h5Kpz.png, but without the box?Ale
That is correct :-)RAHenriksen
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
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

1 Answers

0
votes

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))