0

我有这样的数据:

    yr      X  lower  upper
1 2004 0.2852 0.3927 0.1888
2 2005 0.3710 0.2385 0.5093
3 2006 0.3297 0.2177 0.4557
4 2007 0.2230 0.1424 0.3138
5 2008 0.3028 0.1952 0.4237
6 2009 0.3906 0.2798 0.5226
7 2010 0.3382 0.2343 0.4467

以下是一些可重现的数据:

dt <- structure(list(yr = 2004:2010, X = c(0.2852, 0.371, 0.3297, 0.223, 0.3028, 0.3906, 0.3382), lower = c(0.3927, 0.2385, 0.2177, 0.1424, 0.1952, 0.2798, 0.2343), upper = c(0.1888, 0.5093, 0.4557, 0.3138, 0.4237, 0.5226, 0.4467)), .Names = c("yr", "X", "lower", "upper"), class = "data.frame", row.names = c(NA, -7L))

我想绘制这个,结果将在演示文稿中显示,所以我想让它看起来尽可能好 - 很抱歉使用主观的“好”,但我不知道该怎么说它 !我试过这个:

library(ggplot2)

ggplot(dt, aes(x=yr, y=X, group=1)) +
    geom_line() +
    geom_errorbar(width=.1, aes(ymin=lower, ymax=upper)) +
    geom_point(shape=21, size=3, fill="blue") +
    ylim(0,0.6)

但我不喜欢结果——它看起来简单而无聊: 在此处输入图像描述

4

1 回答 1

1

您可以使用功能区而不是错误栏

dt <- structure(list(yr = 2004:2010, 
    X = c(0.2852, 0.371, 0.3297, 0.223, 0.3028, 0.3906, 0.3382), 
    lower = c(0.3927, 0.2385, 0.2177, 0.1424, 0.1952, 0.2798, 0.2343), 
    upper = c(0.1888, 0.5093, 0.4557, 0.3138, 0.4237, 0.5226, 0.4467)),
  .Names = c("yr", "X", "lower", "upper"), class = "data.frame", 
    row.names = c(NA, -7L))
library(ggplot2)
ggplot(dt, aes(x=yr, y=X, group=1, ymin = lower, ymax = upper)) +
    geom_ribbon(alpha = 0.2) +
    geom_line() +
    geom_point(shape=21, size=3, fill="blue") +
    ylim(0,0.6)

在此处输入图像描述

于 2012-07-22T11:30:37.257 回答