我怎样才能在同一图中绘制参考线Y1
和参考线?Y2
ggplot2
这是我的数据:
year partbuild mean.t sd.t n.t se.tr ci1 ci2
1 2003 Assets 6.072719 11.109798 173 0.8446623 4.417181 7.728257
2 2003 Non-opportunity 3.793043 59.377032 4394 0.8957534 2.037366 5.548720
3 2003 Opportunity 2.650684 7.397618 257 0.4614507 1.746240 3.555127
4 2004 Assets 11.334394 19.609274 173 1.4908655 8.412297 14.256490
5 2004 Non-opportunity 5.922468 38.776455 4394 0.5849760 4.775915 7.069021
6 2004 Opportunity 4.757593 21.598943 257 1.3473051 2.116875 7.398311
7 2005 Assets 13.580937 23.748005 368 1.2379504 11.154554 16.007319
8 2005 Non-opportunity 9.698966 154.769250 4009 2.4443683 4.908004 14.489928
这是我正在使用的代码
y.bar <- ddply(d1a, c('year', 'partbuild'), function(x) mean(x$transfers.cap, na.rm=T))
sd.tr <- ddply(d1a, c('year', 'partbuild'), function(x) sd(x$transfers.cap, na.rm=T))
n.tr <- ddply(d1a, c('year', 'partbuild'), function(x) length(x$transfers.cap))
db2 <- merge(y.bar, sd.tr, by=c('year', 'partbuild'))
db3 <- merge(db2, n.tr, by=c('year', 'partbuild'))
colnames(db3) <- c('year', 'partbuild', 'mean.t', 'sd.t', 'n.t')
p <- ggplot(db3, aes(y=mean.t, x=year, group=partbuild, shape=partbuild))
p + geom_point(aes(colour = partbuild), size=3.5) + geom_line(aes(colour = factor(partbuild)), size=1) + theme_bw() + ylab("Average of Federal Transfers per capita") + xlab("Year") + theme(axis.title.x = element_text(face='bold', size = 15, vjust = .25)) + theme(legend.title=element_blank()) + theme(axis.title.y = element_text(face="bold", size = 15, angle=90)) + scale_fill_discrete(name="") + theme(legend.text = element_text(colour="black", size = 13, face = "bold")) + geom_vline(xintercept = c(2004, 2008), linetype="dashed" )
这是我得到的图片:
但是,我想用n.tr
这些线后面的变量绘制区域。
我怎样才能做到这一点?