I am trying to make boxplots with jitter strips using code from a website (https://z3tt.github.io/beyond-bar-and-box-plots/). The code on that website is shown in the screenshot below.
I am not sure what the "g"s stand for and if those are referring to their dataframe. My code so far is this:
df %>%
geom_boxplot(aes(data = df, x = groupci, y = df$weight_v1_3, color = groupci, fill = groupci)) +
scale_y_continuous(breaks = 1:9) +
scale_color_manual(values = weight_v1_3, guide = "none") +
scale_fill_manual(values = weight_v1_3, guide = "none")
df +
geom_boxplot(alpha = .5, size = 1.5, outlier.size = 5)
df +
geom_boxplot
(aes(fill = groupci, fill = after_scale(colorspace::lighten(fill, .7))),
size = 1.5, outlier.shape = NA) +
geom_jitter(width = .1, size = 7, alpha = .5)
The error messages say: mapping must be created by aes()
and Error in is_reference(x, quote(expr = )) : object 'weight_v1_3' not found.
The variable from my data that I want to portray is called "weight_v1_3". I also want to show boxplots side-by-side of a control and intervention group, similar to the example from the website below. Ultimately, I would even like to show control and intervention group side-by-side and then marked for 3 visits, so 3 pairs of control and intervention in one graph for one variable, here weight. I don't think this is included in the code yet. If anybody knows how to do this additionally, that would be awesome.
I just used the same scaling from the website to see what it would look like and then maybe alter it later. Unfortunately my code does not work yet. Does anybody have some ideas? Thank you in advance!
Sample data:
structure(list(pseudonym = c(1L, 2L, 4L, 5L, 6L, 7L, 3L, 8L,
9L, 10L, 11L, 1L, 2L, 4L, 5L, 6L, 7L, 3L, 8L, 9L, 10L, 11L, 1L,
2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), control.0.1. = c(0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), intervention.0.1. = c(1L,
1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), visit = c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), weight.V1.3 = c(60L,
60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 59L, 59L, 59L,
59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 57L, 57L, 57L, 57L, 57L,
57L, 57L, 57L, 57L)), class = "data.frame", row.names = c(NA,
-31L))