I am struggling with boxplots in R studio. I have a data set that looks like this:
Site | date | Chloride_mgL |
---|---|---|
B | 2021-06-08 12:00:00 | 29.13800 |
D | 2021-06-08 12:00:00 | 29.41100 |
D | 2021-06-15 12:00:00 | 29.92400 |
E | 2021-06-08 12:00:00 | 29.29100 |
A | 2021-06-08 12:00:00 | 29.16800 |
D | 2021-06-22 12:00:00 | 32.79500 |
C | 2021-06-22 12:00:00 | 30.59200 |
Site is characters, date is POSIXct, and Chloride is numeric. I need to make box plots with date on the x axis and Chloride on the y axis, grouped by date. So, for example, I need a box on 2021-06-08 12:00:00 that is made of all of the Chloride values from all of the sites on that date/time. I can get that made, but for some reason when I make it the boxes are tiny and I need them to be bigger, but the width = function just makes the boxes into skinny lines, and not boxes at all.
This is how I make the box plots:
c <- ggplot(sylvan[sylvan$Site %in% c("A", "B", "C", "D", "E", "F", "G") & sylvan$Chloride_mgL > 25, ], aes(x = date, y = Chloride_mgL, group = date)) +
geom_boxplot(outlier.shape = NA, color = "dark blue") + theme_minimal() + labs(y ="Chloride (mg/L)")
c
Which gives this:
Great, but I want bigger boxes. So I try to use the width argument:
c <- ggplot(sylvan[sylvan$Site %in% c("A", "B", "C", "D", "E", "F", "G") & sylvan$Chloride_mgL > 25, ], aes(x = date, y = Chloride_mgL, group = date)) +
geom_boxplot(width = 2, outlier.shape = NA, color = "dark blue") + theme_minimal() + labs(y ="Chloride (mg/L)")
c
And then it turns into this:
How can I make the boxes wider instead of just turning into skinny little lines? Thanks so much!
Edit: Tried @TarJae solution, and it turned out like this:
enter image description here
Read more here: Source link