After a good amount of looking, I can't seem to find the exact answer to my question, so I figured I'd ask.
I want to make a grouped violin plot of a timecourse I have with two conditions ("Control RNAi" and "mex-6 RNAi") using ggplot2. Each of the data points comes from 3 different replicates ("Worm" factor in dataframe), so the dataframe format I have looks like this (with "mean_mex6" being the plotted Y value):
mean_mex6 | RNAi | Time | Worm |
---|---|---|---|
2.4102356 | Control RNAi | 2hr | worm1 |
0.8332575 | Control RNAi | 2hr | worm1 |
2.5093177 | Control RNAi | 2hr | worm1 |
0.8792359 | Control RNAi | 2hr | worm1 |
1.2570116 | Control RNAi | 2hr | worm1 |
1.0671826 | Control RNAi | 2hr | worm1 |
There are many more lines in the dataframe, but the data I showed you above are just some datapoints that came from "worm1" on "Control RNAi" at the "2hr" timepoint.
I want all the individual points plotted in each RNAi group on the violin plot, but I want them plotted so that every datapoint from each "Worm" sample is a different color from the other worms. I have been able to create a grouped violin plot where all the individual points are plotted, but not color coded for each individual worm sample:
library(ggplot2)
ggplot(compiled_allhours, aes(x=Time, y=mean_mex6, colour=RNAi)) +
geom_violin(trim=FALSE) +
scale_x_discrete(limits=c("2hr", "4hr","6hr", "8hr","24hr")) + ##This chooses which data to plot and orders them
geom_quasirandom(aes(x=Time, y=mean_mex6, colour = RNAi), dodge.width = 0.9, varwidth = TRUE) +
ggtitle(expression(paste(italic("mex-6"), " nuclear signal", " - WT"))) +
theme(plot.title = element_text(hjust = 0.5)) + ##Centers the title of the plot
xlab("Time") +
ylab(expression(paste("normalized ", italic("mex-6"), " nuclear signal (A.U.)")))
I included an image of the plot that this makes.[Plot 1] https://i.stack.imgur.com/yvfYW.png
If I try to color the individual points by worm, this is what happens:
library(ggplot2)
ggplot(compiled_allhours, aes(x=Time, y=mean_mex6, colour=RNAi)) +
geom_violin(trim=FALSE) +
scale_x_discrete(limits=c("2hr", "4hr","6hr", "8hr","24hr")) + ##This chooses which data to plot and orders them
geom_quasirandom(aes(x=Time, y=mean_mex6, colour = Worm), dodge.width = 0.9, varwidth = TRUE) +
ggtitle(expression(paste(italic("mex-6"), " nuclear signal", " - WT"))) +
theme(plot.title = element_text(hjust = 0.5)) + ##Centers the title of the plot
xlab("Time") +
ylab(expression(paste("normalized ", italic("mex-6"), " nuclear signal (A.U.)")))
[Plot 2] https://i.stack.imgur.com/aVJwG.png
So basically, I want the second plot, but with all those points merged into the violin plot as is shown in the first graph. Thanks for your help!