【发布时间】:2021-04-10 13:09:07
【问题描述】:
经过大量查找,我似乎无法找到我的问题的确切答案,所以我想我会问。
我想使用 ggplot2 制作具有两个条件(“控制 RNAi”和“mex-6 RNAi”)的时间进程的分组小提琴图。每个数据点都来自 3 个不同的副本(数据帧中的“蠕虫”因子),所以我的数据帧格式如下所示(“mean_mex6”是绘制的 Y 值):
| 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 |
数据框中还有很多行,但我在上面向您展示的数据只是在“2小时”时间点来自“Control RNAi”上的“worm1”的一些数据点。
我希望在小提琴图的每个 RNAi 组中绘制所有单独的点,但我希望将它们绘制成每个“蠕虫”样本的每个数据点与其他蠕虫的颜色不同。我已经能够创建一个分组小提琴图,其中绘制了所有单独的点,但没有为每个单独的蠕虫样本进行颜色编码:
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.)")))
我附上了这张图的图片。[图 1]https://i.stack.imgur.com/yvfYW.png
如果我尝试通过蠕虫为各个点着色,会发生以下情况:
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.)")))
[情节2]https://i.stack.imgur.com/aVJwG.png
所以基本上,我想要第二个图,但所有这些点都合并到小提琴图中,如第一张图所示。感谢您的帮助!
【问题讨论】:
标签: r ggplot2 violin-plot