geom_errorbar - "没有统计信息StatHline" [英] geom_errorbar - "No stat called StatHline"

查看:267
本文介绍了geom_errorbar - "没有统计信息StatHline"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法重新生成我以前使用下面的代码生成的图(使用 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),第5天,第1天,第9天,第5天))

library(ggplot2)
plot_data< - ggplot()+
ylim(-2.5,0.5)+
geom_point(data = data,aes(x = Day,y = CorrectedIntensity),size = 7,
color =royalblue3,alpha = 0.30)+
geom_errorbar(data = data,aes(x = Day,y = CorrectedIntensity,ymax = .. y ..,ymin = .. y ..),
stat =hline,yintercept =意思是,width = 0.3,color =royalblue3,
size = 1.25)+
stat_summary(data = data,aes(x = Day,y = CorrectedIntensity),
fun.ymax =函数(i)平均值(i)+ sd(i),
fun.ymin =函数(i)平均值(i) - sd(i),
geom =errorbar,width = 0.1 ,color =royalblue3)

这就是我想要的情节k like:



解决方案

div>

我认为这可以归结为


I can't seem to re-generate plots (using ggplot2) that I previously generated using the code below. I now get the error message "No stat called StatHline". Is there a replacement?

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")

This is what I want the plot to look like:

解决方案

I think this boils down to major changes in ggplot2.

Here are a couple of options. The first uses points with shape='-' for the horizontal bars. The second uses geom_errorbar as you had used previously, but via 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.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', width=0.1, color='royalblue3') +
  # lines for means, using geom=errorbar
  stat_summary(fun.y=mean, aes(ymin=..y.., ymax=..y..), 
               geom='errorbar', width=0.3, color='royalblue3', size=1.25) +
  # line connecting means
  stat_summary(fun.y=mean, colour='royalblue3', geom='line', aes(group=1), lty=2)

这篇关于geom_errorbar - &quot;没有统计信息StatHline&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆