Side-by-side plots with ggplot2

后端 未结 13 2483
轮回少年
轮回少年 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:27

    Yes, methinks you need to arrange your data appropriately. One way would be this:

    X <- data.frame(x=rep(x,2),
                    y=c(3*x+eps, 2*x+eps),
                    case=rep(c("first","second"), each=100))
    
    qplot(x, y, data=X, facets = . ~ case) + geom_smooth()
    

    I am sure there are better tricks in plyr or reshape -- I am still not really up to speed on all these powerful packages by Hadley.

提交回复
热议问题