ggplot2:向scatterplot中的每个点添加两个错误条 [英] ggplot2 : Adding two errorbars to each point in scatterplot

查看:371
本文介绍了ggplot2:向scatterplot中的每个点添加两个错误条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在散点图中的每个点上绘制两个误差线。通常情况下垂直误差线对应于点y值的误差,但我需要添加与X轴(水平线)相关的误差线。我可以用一些abline命令来做到这一点,但认为可能有一个更聪明的方法来做到这一点与ggplot2?

为了完成,继续我的评论,这是一个简单的(虽然很丑)的例子:

  df < - 数据.frame(x = 1:10,
y = 1:10,
ymin =(1:10) - runif(10),
ymax =(1:10)+ runif(10 ),
xmin =(1:10) - runif(10),
xmax =(1:10)+ runif(10))

ggplot(data = df, aes(x = x,y = y))+
geom_point()+
geom_errorbar(aes(ymin = ymin,ymax = ymax))+
geom_errorbarh(aes(xmin = xmin, xmax = xmax))


I need to plot two error-bars on each point in a scatterplot. The usual is vertical error-bars that corresponds to the error on the points y-value, but I need to add the error-bar associated with the X-axis (horizontal) as well. I could probably do this with some abline command, but thought there might be a more clever way to do it with ggplot2?

解决方案

Just for completion's sake, following up on my comment, here is a simply (albeit ugly) example:

df <- data.frame(x = 1:10,
                 y = 1:10,
                 ymin = (1:10) - runif(10),
                 ymax = (1:10) + runif(10),
                 xmin = (1:10) - runif(10),
                 xmax = (1:10) + runif(10))

ggplot(data = df,aes(x = x,y = y)) + 
    geom_point() + 
    geom_errorbar(aes(ymin = ymin,ymax = ymax)) + 
    geom_errorbarh(aes(xmin = xmin,xmax = xmax))

这篇关于ggplot2:向scatterplot中的每个点添加两个错误条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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