我不知道你是否成功得到你的阴谋,如果你有兴趣,我找到了一种方法:
首先,我计算Values 的Values 的sd 和@Gregor 的建议,我创建了一个新列,它是@987654330 的串联@和Condition
library(dplyr)
df2 = df%>%
group_by(Sample,Condition) %>%
summarise(Mean = mean(Value), Sd = sd(Value)) %>%
mutate(New_Var = paste0(Sample,Condition))
然后,我们可以绘制数据:
library(ggplot2)
ggplot(df2, aes(x = New_Var, y = Mean, fill = Condition)) +
geom_bar(stat = "identity", color = "black",position = position_dodge(), width = 0.7) +
geom_errorbar(aes(ymin = Mean - Sd, ymax = Mean + Sd), width = .2, position = position_dodge(.9)) +
scale_fill_manual(values = c("black","grey","red"),
labels = c("Control","Condition 1", "Condition 2")) +
scale_x_discrete(limits = c("blankcontrol","AC1","BC1","CC1","AC2","BC2","CC2") , labels = c("Blank","A","B","C","A","B","C")) +
theme(axis.text.x = element_text(face = "bold",angle = 45),
legend.title = element_blank()) +
xlab("") +
scale_y_continuous(limits = c(0,15), breaks = c(0,5,10,15))
情节看起来与您从 GraphPad 获得的情节非常相似。我同意这不是一件容易的事,但如果你真的想要这个情节,你可以得到它。
编辑 - 在图表上添加单个值
library(dplyr)
dfX= df %>%
mutate(New_Var2 = paste0(Sample,Condition))
library(ggplot2)
ggplot(df2, aes(x = New_Var, y = Mean, fill = Condition)) +
geom_bar(stat = "identity", color = "black",position = position_dodge(), width = 0.7) +
geom_errorbar(aes(ymin = Mean - Sd, ymax = Mean + Sd), width = .2, position = position_dodge(.9)) +
scale_fill_manual(values = c("black","grey","red"),
labels = c("Control","Condition 1", "Condition 2")) +
scale_x_discrete(limits = c("blankcontrol","AC1","BC1","CC1","AC2","BC2","CC2") , labels = c("Blank","A","B","C","A","B","C")) +
theme(axis.text.x = element_text(face = "bold",angle = 45),
legend.title = element_blank()) +
xlab("") +
scale_y_continuous(limits = c(0,15), breaks = c(0,5,10,15))+
geom_jitter(data = dfX, aes(x = New_Var2, y = Value), position=position_jitter(0.3), show.legend = F)
您会得到以下图表:
但是,每个条件只有三个点,我宁愿将均值表示为单个点,并以 sd 作为误差线。类似的东西。
ggplot(df2, aes(x = New_Var, y = Mean, group = Condition)) +
geom_point(aes(shape = Condition, color= Condition), stat = "identity", position = position_dodge(), size = 2) +
geom_errorbar(aes(ymin = Mean - Sd, ymax = Mean + Sd, color = Condition), width = .2, position = position_dodge(.9)) +
scale_shape_manual(values=c(15, 16, 17))+
scale_color_manual(values = c("black","darkgrey","darkred"), labels = c("Control","Condition 1", "Condition 2")) +
scale_x_discrete(limits = c("blankcontrol","AC1","BC1","CC1","AC2","BC2","CC2") , labels = c("Blank","A","B","C","A","B","C")) +
theme(axis.text.x = element_text(face = "bold",angle = 45),
legend.title = element_blank()) +
xlab("") +
scale_y_continuous(limits = c(0,15), breaks = c(0,5,10,15))+
geom_jitter(data = dfX, aes(x = New_Var2, y = Value, shape = Condition),
position=position_jitter(0.3), color = adjustcolor("black",alpha.f = 0.6),
show.legend = F, size = 2)
结果图:
但这只是我的个人意见,这取决于你;)