【问题标题】:Error bars are not plotted when axes are reversed (plotCI from package plotrix)反转轴时不绘制误差线(来自包 plotrix 的 plotCI)
【发布时间】:2015-07-15 13:58:14
【问题描述】:

我想更改带有垂直和水平误差线的绘图的原点。我正在使用“plotrix”包中的 plotCI 函数进行绘图。

一个非常简短的可重现示例:

x <- c(1, 2)
y <- c(3, 4)
err.x <- c(0.5, 0.2)
err.y <- c(0.25, 0.3)
plotCI(x, y, uiw = err.x, err = "x",
       ylim = range(y+err.y, y-err.y))
plotCI(x, y, uiw = err.y, err = "y", add = T)

在这个情节中一切都很好。我得到了水平和垂直误差线。

plotCI(x, y, uiw = err.x, err = "x",
       ylim = rev(range(y+err.y, y-err.y)))
plotCI(x, y, uiw = err.y, err = "y", add = T)

在这里,我只得到水平误差线。似乎 y 轴的反转没有被第二次调用 plotCI '识别'。

有什么想法吗?!?非常感谢!

【问题讨论】:

    标签: r plot axes plotrix


    【解决方案1】:

    我喜欢plotrix 及其相关功能,但我认为您尝试做的事情受到arrows() 功能的阻碍,plotCI() 依赖于不遵守ylim 反转。你可以改用ggplot2 来获得你想要的情节:

    x <- c(1, 2)
    y <- c(3, 4)
    err.x <- c(0.5, 0.2)
    err.y <- c(0.25, 0.3)
    
    library(ggplot2)
    ggplot(data.frame(x,y,err.x,err.y), aes(x=x, y=y)) +
      geom_point() + 
      geom_errorbar(aes(ymin=y-err.y, ymax=y+err.y), width=0.05) + 
      geom_errorbarh(aes(xmin=x-err.x, xmax=x+err.x), height=0.05) + 
      scale_y_reverse()
    

    【讨论】:

    • 嗨,阿甘,非常感谢您的回答。我想在这种情况下我毕竟不会使用 plotrix 。您的解决方案看起来确实更灵活。
    猜你喜欢
    • 2014-07-10
    • 1970-01-01
    • 2013-03-15
    • 2022-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    相关资源
    最近更新 更多