1

我对 R 非常陌生,并且正在尝试在 ggplot2 中创建一个散点图,这会影响散点图,其中每个符号的宽度和高度由两个变量控制。我想出了一个使用 geom_errorbar 和 geo_errorbarh (下面的代码)的解决方法,它产生了我正在寻找的东西,但我希望能够删除错误 x/y 中间交叉线并留下一个框每个数据点,我可以着色(我只需要它们是一种颜色)。我正在谈论的事情类型的一个例子是:http: //imbie.org/about-the-project/ice-sheet-mass-balance-measurements/

我的数据的一个子集是(我希望我正确使用了 dput() ):

structure(list(Year = c(2000L, 1995L, 1986L, 1977L, 1977L, 1973L, 
1973L, 1969L, 1965L, 1961L), RSL = c(0.02, 0.02, 0, -0.01, -0.07, 
0, -0.11, -0.1, -0.16, -0.07), Age_error = c(2L, 1L, 5L, 4L, 
3L, 4L, 3L, 2L, 2L, 3L), RSL_error = c(0.03, 0.04, 0.03, 0.03, 
0.05, 0.03, 0.05, 0.05, 0.05, 0.03), plus_error = c(0.05, 0.06, 
0.03, 0.02, -0.02, 0.03, -0.06, -0.05, -0.11, -0.04), minus_error = c(-0.01, 
-0.02, -0.03, -0.04, -0.12, -0.03, -0.16, -0.15, -0.21, -0.1), 
plus_age = c(2002L, 1996L, 1991L, 1981L, 1980L, 1977L, 1976L, 
1971L, 1967L, 1964L), minus_age = c(1998L, 1994L, 1981L, 
1973L, 1974L, 1969L, 1970L, 1967L, 1963L, 1958L), total_RSLerror = c(0.06, 
0.08, 0.06, 0.06, 0.1, 0.06, 0.1, 0.1, 0.1, 0.06), total_Ageerror = c(4L, 
2L, 10L, 8L, 6L, 8L, 6L, 4L, 4L, 6L)), .Names = c("Year", 
"RSL", "Age_error", "RSL_error", "plus_error", "minus_error", 
"plus_age", "minus_age", "total_RSLerror", "total_Ageerror"), class = "data.frame", 
row.names = c  ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"))

我目前得到的代码是:

    ggplot(data, aes(x=Year, y=RSL)) + geom_errorbar(aes(ymin=minus_error, ymax=plus_error, width=total_Ageerror)) + geom_errorbarh(aes(xmax=plus_age, xmin=minus_age, height=total_RSLerror)) + theme_bw()

非常感谢你的期待。请让我知道我是否需要发送其他任何内容,或者我是否输入错误。

4

1 回答 1

4

您可以geom_rect()使用您的plus_minus_变量作为maxmin坐标(将您的数据命名为df)来实现它。

ggplot(df,aes(xmin=minus_age,xmax=plus_age,ymin=minus_error,ymax=plus_error))+
  geom_rect(fill="green",color="black")

在此处输入图像描述

于 2013-06-24T14:46:44.397 回答