【问题标题】:How to show error bars in scatter plots using R如何使用 R 在散点图中显示误差线
【发布时间】:2013-04-24 06:46:46
【问题描述】:

所以我有类似的数据

Value   Number
3   1.5
6   1.67
9   1.7
12  1.6
15  1.7
18  1.8
21  1.9
24  1.98
27  1.98
30  1.8
33  1.84
36  1.5
39  1.7
42  1.9
45  1.9
48  2.0
51  1.21
54  1.4
57  2.34
60  2.5
63  2.1
66  1.77

如何使用标准误差线制作散点图....我查了一下,它似乎是这样的

errbar(df$Value, df$Number, yplus, yminus, cap = 0.015,
       xlab= deparse(substitute(x)),
       ylab= deparse(substitute(y)))

但是我对 yplus 不熟悉,yminus?和deparse?? 还有其他方法可以做到这一点吗?我尝试使用 ggplot 并使用 install.packages(ggplot2) 下载它,但 R 一直说它找不到它并使用此代码进行尝试

> ggplot(data=dataset,aes(x=df$Value,y=df$Number,colour=Code,linetype=Group,ymin=Mean-SE,ymax=Mean+SE)) 
Error: could not find function "ggplot"
> + geom_line()
Error: could not find function "geom_line"
> + scale_x_continuous(breaks=c(1,2))
Error: could not find function "scale_x_continuous"
> + scale_linetype_manual(values=c(2,1))
Error: could not find function "scale_linetype_manual"
> + geom_point()
Error: could not find function "geom_point"
> + geom_errorbar(width=.1,position='dodge')
Error: could not find function "geom_errorbar"

另外,我应该如何在一张图中用相同的 x 轴值绘制 2 个散点图并显示误差线? 谢谢大家...任何建议都会被欣赏

【问题讨论】:

  • 你熟悉?library吗?

标签: r scatter-plot standard-error


【解决方案1】:

您看到的错误是因为ggplot2 包尚未加载。在脚本中添加library(ggplot2) 可以解决这个问题。这当然是假设安装了ggplot2 包。如果没有,请使用install.packages("ggplot2") 解决此问题。

【讨论】:

    【解决方案2】:

    或者,您可以使用 R 的 gplots 包,它非常好且易于处理(至少在我看来)。

    # Required package
    library(gplots)
    
    # Sample data
    x <- seq(3, 66, 3)
    y <- c(1.5, 1.67, 1.7, 1.6,  1.7,  1.8,  1.9,  1.98,  1.98,  1.8,  1.84,  
           1.5,  1.7,  1.9,  1.9,  2.0,  1.21,  1.4,  2.34,  2.5,  2.1,  1.77)
    xy <- data.frame(x, y)
    
    # Plotting
    plotCI(x, y, 
           uiw = .5, gap = 0, pch = 22, pt.bg = "green")
    

    当然,您必须将参数 uiwliw 替换为错误向量。

    干杯,弗洛里安

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      相关资源
      最近更新 更多