1
我想在用ggplot和分面生成的2個地塊中添加箭頭。問題:如何避免兩個圖形中箭頭的複製?我想添加個別箭頭到每個情節。 下面是一個例子:在多個地塊中添加單獨的箭頭
library(ggplot2)
# data frame with fake data
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
# ggplot with faceting
xp <- ggplot(xdf,aes(x=x,y=y)) +
geom_line() +
facet_grid(. ~ z)
xp
# location of the arrow: x=4, y= on the top
(f1x4 <- xdf[4,"y"])+1
xp + geom_segment(aes(x=4,xend=4,y=f1x4+3,yend=f1x4)
, arrow=arrow(length=unit(0.4,"cm")
)
) +
geom_text(aes(x=4,y=f1x4+5, label="a"))
事件描述: 箭頭被放置在兩端面在同一區域中。我如何選擇一個特定的陰謀放置箭頭?
非常感謝。這就是我想要的,它不知道如何簡單的解決方案。 – giordano 2012-02-28 07:28:14