如何在R中使用grid.arrange并排排列绘图框/边框 [英] How to draw a box/border around plots arranged side by side using grid.arrange in R
问题描述
我使用ggplot创建了两张图,如下所示:
library(ggplot2)
library(gridExtra)$ (虹膜,aes(Sepal.Width,Sepal.Length))+ geom_point()
g2< - ggplot(虹膜,aes(Petal.Width,Petal.Length))+ geom_point()
grid.arrange(g1,g2,ncol = 2)
喜欢在grid.arrange生成的两个并排图上绘制边框/框...我认为这与使用grid.border有关,但我不确定如何完全如此。感谢任何帮助?
使用ggplot帮助页面中的示例:
(pre> gg < - df < - data.frame(gp = factor(rep(letters [1:3],each = 10)),
y = rnorm (30))
library(plyr)
ds < - ddply(df,。(gp),summary,mean = mean(y),sd = sd(y))
gg2 <-ggplot(df,aes(x = gp,y = y))+
geom_point()+
geom_point(data = ds,aes(y = mean),
color ='red',size = 3)+ theme(panel.border = element_rect(fill = NA))
grid.arrange(gg2,gg2,ncol = 2)
$ b
也许这取决于你的身材:
gg2 <-ggplot(df,aes(x = gp,y = y))+
geom_point()+
geom_point(data = ds,aes(y = mean),
$ b grid.arrange(gg2,gg2,$ b color ='red',size = 3)+ theme(plot.background = element_rect(size = 3,linetype =solid,color =black ncol = 2)
如果你只是想要一个边界矩形:
grid.rect (.5,.5,width =单位(.99,npc),height =单位(0.99,npc),
gp = gpar(lwd = 3,fill = NA,col =blue ))
I have created two plots using ggplot as follows:
library(ggplot2)
library(gridExtra)
g1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point()
g2 <- ggplot(iris, aes(Petal.Width, Petal.Length)) + geom_point()
grid.arrange(g1, g2, ncol=2)
I would like to draw a border/box around the two side by side plots produced by grid.arrange...I think it is something to do with using grid.border, but am not sure of how exactly to do so. Will appreciate any help?
Using an example from the ggplot help page:
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)
Or perhaps this depending on your 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)
If you just want a bordering rectangle:
grid.rect(.5,.5,width=unit(.99,"npc"), height=unit(0.99,"npc"),
gp=gpar(lwd=3, fill=NA, col="blue"))
这篇关于如何在R中使用grid.arrange并排排列绘图框/边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!