very beginner question here: I have a dataset of 4 columns of values and I need to create a graph with 4 boxplots showing average and standard deviation, and I wanted to know how to also show the individual observations as points (with ggplot2). Thank you for your help!!!!
Asked
Active
Viewed 425 times
0
-
3Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including (at least) a snippet of your data or some fake data. – stefan Aug 10 '22 at 19:17
-
1This said: At least for the first step which involves reshaping your data you could have a look at https://stackoverflow.com/questions/53971524/how-to-reshape-data-to-create-facets-of-boxplots-of-multiple-variables-in-r – stefan Aug 10 '22 at 19:17
1 Answers
0
This is relatively simple, as you can add multiple geom_
s in ggplot.
Here is a small example that showcases the geom_boxplot
in combination with geom_jitter
.
In order to also be able to show outliers in a box plot (if that is what you want), you can add color or different point-types with e.g. geom_boxplot(outlier.color = "red")
.
library(tidyverse)
iris %>%
ggplot(aes(x = Species, y = Sepal.Length)) +
geom_boxplot(outlier.colour = "red") + # Add the boxplot geom
geom_jitter(width = 0.1) # Add the points with a random jitter on the X-axis
Created on 2022-08-11 by the reprex package (v2.0.0)

mhovd
- 3,724
- 2
- 21
- 47
-
thank you very much! Could you please indicate me how to move one of the species to the left or to the right in this particular graph? – Ask Aug 11 '22 at 17:59
-
Are you asking to change the order, or create a space between the groups? – mhovd Aug 12 '22 at 08:17
-
I wanted to know how to change the order (left/right) of the boxplots in a custom way – Ask Aug 13 '22 at 06:09