1
在 Adding individual arrows in multiple plots 我描述了由于数学咖啡已解决的问题。刻面:在多个图中添加单独的箭头不起作用
我的问题是如何添加一个单一的箭头只有一个方面。最近我安装了R的新版本:
平台把i386-pc-mingw32的
version.string [R版本2.14.2(2012-02-29)ggplot2_0.9.0
这里是代码示例
# data frame
xdf <- data.frame(x=rep(1:10,2)
,y=c(2*c(1:10)+rnorm(10,0,3), 4*c(1:10)+rnorm(10,0,5))
,z=rep(c("A","B"),each=10)
)
xdf
# plot
ggplot with faceting
xp <- ggplot(xdf,aes(x=x,y=y)) +
geom_line() +
facet_grid(. ~ z)
xp
# location of the arrow: x=4, y=y+1 on the top of the first facet (A)
(f1x4 <- xdf[4,"y"]+1)
# add arrow and label
xp + geom_segment(aes(x=4,xend=4,y=f1x4+3,yend=f1x4,z='A') # <-- see the z='A'
, arrow=arrow(length=unit(0.4,"cm")
)
) +
geom_text(aes(x=4,y=f1x4+5, label="a",z='A')) # <-- see the z='A'
应该发生的事情:箭头应只对小A. 会发生什么创建:箭头是在两个方面创造了A和B
有没有人知道如何解决这个问题?