combine plots with different variable relations

2019-06-14 18:15发布

The df has three normal variables:a,b,c and one group variable: d.

df<-data.frame(c(5,1,1,2,3,7,5,4,2,1),c(1:10),c(1,1,1,1,1,2,1,2,1,2),c(rep('o',5),rep('m',5)))
colnames(df)<-c('a','b','c','d')

Considering these two plots:

  1. a-b plot grouped by d:qplot(a,b,data=df,geom = 'point')+facet_wrap(~d,nrow = 2)

  2. b-c plot grouped by d:qplot(b,c,data=df,geom = 'point')+facet_wrap(~d,nrow = 2)

Is it possible to combine these two plots into one plot using R?

标签: r plot ggplot2
1条回答
Melony?
2楼-- · 2019-06-14 18:49

Do you want somethign like the following?

library(grid)
library(gridExtra)
grid.arrange(qplot(a,b,data=df,geom = 'point')+facet_wrap(~d,nrow = 2),
             qplot(b,c,data=df,geom = 'point')+facet_wrap(~d,nrow = 2),
             ncol=2)

enter image description here

查看更多
登录 后发表回答