I have a data set with a number of grouped treatments. In parallel in a couple of independent groups I collected a positive and negative control. For plotting purposes and further analysis I would like to duplicate the control groups for each individual treatment groups. So my plots turn from this:
to this:
In dplyr, I have figured out how to identify and generate a column with the right control values, but the challenge is how to duplicate complete rows of the dataset and append them, rather than just adding a 'postive control' and 'negative control' column for each relevant groups. That approach kinda works, but means that you can really only store a summary value (e.g. mean) that gets copied across each treatment, rather than maintaing the individual readouts.
librar(ggplot)
before <- structure(list(group = c("grp1", "grp1", "grp1", "grp1",
"grp2", "grp2", "grp2", "grp2", "grp3", "grp3", "grp3", "grp3",
"neg", "neg", "pos", "pos"), treatment = c("A", "B", "C",
"D", "A", "B", "C", "D", "A", "B", "C", "D", "none", "none",
"none", "none"), value = c(3L, 5L, 7L, 9L, 2L, 4L, 6L, 8L, 3L,
4L, 6L, 9L, 12L, 10L, 1L, 2L)), class = "data.frame", row.names = c(NA, -16L))
ggplot(data = before, aes(x=treatment, y=value)) + geom_boxplot() + facet_wrap (~group)
after <- structure(list(group = c("grp1", "grp1", "grp1", "grp1", "grp1", "grp1",
"grp1", "grp1", "grp2", "grp2", "grp2", "grp2", "grp2", "grp2",
"grp2", "grp2", "grp3", "grp3", "grp3", "grp3", "grp3", "grp3",
"grp3", "grp3"), treatment = c("A", "B", "C", "D", "neg", "neg",
"pos", "pos", "A", "B", "C", "D", "neg", "neg", "pos", "pos",
"A", "B", "C", "D", "neg", "neg", "pos", "pos"), value = c(3L,
5L, 7L, 9L, 12L, 10L, 1L, 2L, 2L, 4L, 6L, 8L, 12L, 10L, 1L, 2L,
3L, 4L, 6L, 9L, 12L, 10L, 1L, 2L)), class = "data.frame", row.names = c(NA, -24L))
ggplot(data = after, aes(x=treatment, y=value)) + geom_boxplot() + facet_wrap (~group)


