Side-by-side plots with ggplot2

后端 未结 13 2399
轮回少年
轮回少年 2020-11-22 02:06

I would like to place two plots side by side using the ggplot2 package, i.e. do the equivalent of par(mfrow=c(1,2)).

For example, I would like to have t

13条回答
  •  有刺的猬
    2020-11-22 02:28

    Using the patchwork package, you can simply use + operator:

    library(ggplot2)
    library(patchwork)
    
    p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
    p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
    
    
    p1 + p2
    

提交回复
热议问题