使用ggplot/stat\U summary为两个单独的组添加多行平均值

使用ggplot/stat\U summary为两个单独的组添加多行平均值,r,ggplot2,R,Ggplot2,我是新手 我试图为两个不同的基因创建基因表达2^-dCt值(数据框中的p2ndCt)的抖动图,以及代表平均值的两条单独的线。我的样本是一系列有序的细胞系。我将数据保存在data.frame中,如下所示: Sample gene dCt p2ndCt 1 K562 naive e14a2 -1.34 2.531513e+00 2 DMSO ctrl e14a2 -0.40 1.319508e+00 3 0.5 nM e14a2 -1.93 3.810

我是新手

我试图为两个不同的基因创建基因表达2^-dCt值(数据框中的p2ndCt)的抖动图,以及代表平均值的两条单独的线。我的样本是一系列有序的细胞系。我将数据保存在data.frame中,如下所示:

       Sample  gene   dCt       p2ndCt
1  K562 naive e14a2 -1.34 2.531513e+00
2   DMSO ctrl e14a2 -0.40 1.319508e+00
3      0.5 nM e14a2 -1.93 3.810552e+00
4        1 nM e14a2 -3.06 8.339726e+00
5        2 nM e14a2 -4.17 1.800094e+01
6      3.5 nM e14a2 -4.70 2.599208e+01
7        5 nM e14a2 -3.58 1.195879e+01

我想让stat_summary()在每个样本中将e14a2平均值与e6a2平均值分开,但是我不确定如何在现有的data.frame中做到这一点。我尝试过以下代码:

##BCR-ABL1 dCt qPCR graph
BCRABL1_dCt <- read.csv('~/Manjaro/workspace/BCR-ABL1_dCt.csv')
BCRABL1_dCt$Sample <- factor(BCRABL1_dCt$Sample, levels = c('K562 naive', 'DMSO ctrl', '0.5 nM', '1 nM', '2 nM', '3.5 nM', '5 nM', '10 nM', '15 nM', '25 nM', '50 nM', '200 nM'))

BCRABL1_dCt_plot <- ggplot(BCRABL1_dCt, aes(x = Sample, y = p2ndCt, color = gene)) + geom_jitter(width = 0.1, height = 0) + stat_summary(aes(y = p2ndCt, group = 1), fun = mean, geom = 'line', size = 1, color = 'red')
e14a2_dCt_plot
##BCR-ABL1 dCt qPCR图

BCRABL1_dCt使用提供的数据片段运行代码,通过
示例给出一行方法:


图书馆(GG2)
ggplot(BCRABL1_dCt,aes(x=样本,y=p2ndCt,颜色=基因))+
几何抖动(宽度=0.1,高度=0)+
统计汇总(aes(y=p2ndCt,组=1),fun=mean,geom=line,size=1,color=red)

但是,使用
group=gene
而不是
group=1
为每个
基因提供了一行平均值:

ggplot(BCRABL1\u dCt,aes(x=Sample,y=p2ndCt,color=gene))+
几何抖动(宽度=0.1,高度=0)+
统计汇总(aes(y=p2ndCt,组=基因),fun=平均值,geom=直线,大小=1,颜色=红色)

数据

BCRABL1_dCt <- read.table(text = "       Sample  gene   dCt       p2ndCt
1  K562_naive e14a2 -1.34 2.531513e+00
2   DMSO_ctrl e14a2 -0.40 1.319508e+00
3      0.5_nM e14a2 -1.93 3.810552e+00
4        1_nM e14a2 -3.06 8.339726e+00
5        2_nM e14a2 -4.17 1.800094e+01
6      3.5_nM e14a2 -4.70 2.599208e+01
7        5_nM e14a2 -3.58 1.195879e+01
67       5_nM  e6a2 -2.06 4.169863e+00
68      10_nM  e6a2 -0.02 1.013959e+00
69      15_nM  e6a2  7.52 5.448217e-03
70      25_nM  e6a2  0.75 5.946036e-01", header = TRUE)

BCRABL1_dCt$Sample <- gsub("_", " ", BCRABL1_dCt$Sample)
BCRABL1_dCt$Sample <- factor(BCRABL1_dCt$Sample, levels = c('K562 naive', 'DMSO ctrl', '0.5 nM', '1 nM', '2 nM', '3.5 nM', '5 nM', '10 nM', '15 nM', '25 nM', '50 nM', '200 nM'))

BCRABL1\u dCt可能
group=gene
而不是
stat\u summary
中的
group=1
?我已经尝试了group='gene'和group=gene,它们都产生了与group=1相同的图形。不幸的是,在阅读了group参数后,我明白了为什么group=gene应该在那里工作。我不确定stat_summary是直接从data.frame调用,还是通过ggplot()调用。我只是补充了我的建议作为回答。也许这有助于找出或澄清问题所在。嗨,Stefan,我再试了一次,效果很好,非常感谢!
BCRABL1_dCt <- read.table(text = "       Sample  gene   dCt       p2ndCt
1  K562_naive e14a2 -1.34 2.531513e+00
2   DMSO_ctrl e14a2 -0.40 1.319508e+00
3      0.5_nM e14a2 -1.93 3.810552e+00
4        1_nM e14a2 -3.06 8.339726e+00
5        2_nM e14a2 -4.17 1.800094e+01
6      3.5_nM e14a2 -4.70 2.599208e+01
7        5_nM e14a2 -3.58 1.195879e+01
67       5_nM  e6a2 -2.06 4.169863e+00
68      10_nM  e6a2 -0.02 1.013959e+00
69      15_nM  e6a2  7.52 5.448217e-03
70      25_nM  e6a2  0.75 5.946036e-01", header = TRUE)

BCRABL1_dCt$Sample <- gsub("_", " ", BCRABL1_dCt$Sample)
BCRABL1_dCt$Sample <- factor(BCRABL1_dCt$Sample, levels = c('K562 naive', 'DMSO ctrl', '0.5 nM', '1 nM', '2 nM', '3.5 nM', '5 nM', '10 nM', '15 nM', '25 nM', '50 nM', '200 nM'))