我似乎无法重新生成ggplot2
我之前使用下面的代码生成的图(使用).我现在收到错误消息"No stat called StatHline"
.有替代品吗?
data <- data.frame( CorrectedIntensity=c(0, -0.66, -0.37, 0, -1.04, -0.38, 0, -1.89, -1.50), Day=c("Day 1", "Day 9", "Day 5", "Day 1", "Day 9", "Day 5", "Day 1", "Day 9", "Day 5")) library(ggplot2) plot_data <- ggplot() + ylim(-2.5, 0.5) + geom_point(data=data, aes(x=Day, y=CorrectedIntensity), size=7, colour="royalblue3", alpha=0.30) + geom_errorbar(data=data, aes(x=Day, y=CorrectedIntensity, ymax=..y.., ymin=..y..), stat = "hline", yintercept = "mean", royalblue3", size=1.25) + stat_summary(data=data, aes(x=Day, y=CorrectedIntensity), fun.ymax=function(i) mean(i) + sd(i), fun.ymin=function(i) mean(i) - sd(i), geom="errorbar", royalblue3")
这就是我希望情节看起来像:
我认为这归结为主要变化ggplot2
.
这里有几个选项.第一个使用带有shape='-'
水平条的点.第二种用途geom_errorbar
就像你以前用过的那样,但通过stat_summary
.
ggplot(data, aes(x=Day, y=CorrectedIntensity)) + ylim(-2.5, 0.5) + # data points geom_point(size=7, colour="royalblue3", alpha=0.30) + # +/- standard deviation stat_summary(fun.data=function(...) mean_sdl(..., mult=1), geom='errorbar', royalblue3') + # points for mean, using hyphens for point shape stat_summary(fun.y=mean, colour='royalblue3', geom='point', shape='-', size=30) + # line connecting means stat_summary(fun.y=mean, colour='royalblue3', geom='line', aes(group=1), lty=2)
ggplot(data, aes(x=Day, y=CorrectedIntensity)) + ylim(-2.5, 0.5) + # data points geom_point(size=7, colour="royalblue3", alpha=0.30) + # +/- standard deviation stat_summary(fun.data=function(...) mean_sdl(..., mult=1), geom='errorbar', royalblue3') + # lines for means, using geom=errorbar stat_summary(fun.y=mean, aes(ymin=..y.., ymax=..y..), geom='errorbar', royalblue3', size=1.25) + # line connecting means stat_summary(fun.y=mean, colour='royalblue3', geom='line', aes(group=1), lty=2)