gpt4 book ai didi

r - geom_errorbar - "No stat called StatHline"

转载 作者:行者123 更新时间:2023-12-02 01:37:06 30 4
gpt4 key购买 nike

我似乎无法重新生成之前使用下面的代码生成的绘图(使用ggplot2)。我现在收到错误消息“没有名为 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", width=0.3, colour="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", width=0.1, colour="royalblue3")

这就是我想要的情节:

enter image description here

最佳答案

我认为这可以归结为major changes in 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', width=0.1, color='royalblue3') +
# points for mean, using hyphens for point shape
stat_summary(fun=mean, colour='royalblue3', geom='point', shape='-', size=30) +
# line connecting means
stat_summary(fun=mean, colour='royalblue3', geom='line', aes(group=1), lty=2)

enter image description here

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', width=0.1, color='royalblue3') +
# lines for means, using geom=errorbar
stat_summary(fun=mean, aes(ymin=..y.., ymax=..y..),
geom='errorbar', width=0.3, color='royalblue3', size=1.25) +
# line connecting means
stat_summary(fun=mean, colour='royalblue3', geom='line', aes(group=1), lty=2)

enter image description here

关于r - geom_errorbar - "No stat called StatHline",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34734218/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com