使用來自ggplot幫助頁面的例子:
gg <- df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30))
library(plyr)
ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))
gg2 <-ggplot(df, aes(x = gp, y = y)) +
geom_point() +
geom_point(data = ds, aes(y = mean),
colour = 'red', size = 3)+theme(panel.border=element_rect(fill=NA))
grid.arrange(gg2,gg2, ncol=2)
或許這取決於你meeaning:
gg2 <-ggplot(df, aes(x = gp, y = y)) +
geom_point() +
geom_point(data = ds, aes(y = mean),
colour = 'red', size = 3)+theme(plot.background = element_rect(size=3,linetype="solid",color="black"))
grid.arrange(gg2,gg2, ncol=2)
如果你只是想要一個邊界矩形:
grid.rect(.5,.5,width=unit(.99,"npc"), height=unit(0.99,"npc"),
gp=gpar(lwd=3, fill=NA, col="blue"))
歡迎去吧!你可能會被低估,因爲通常是一個好主意,用完整的[可重現的]發佈問題(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example )示例以及可以通過複製粘貼運行的完整代碼。 – tonytonov 2014-09-02 07:41:32
道歉...第一次發帖。感謝編輯 – 2014-09-02 10:18:44