Align multiple ggplot2 plots with grid

后端 未结 3 1576
情歌与酒
情歌与酒 2020-12-01 18:49

Context

I want to plot two ggplot2 on the same page with the same legend. http://code.google.com/p/gridextra/wiki/arrangeGrob discribes, how to do this. This alrea

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 19:16

    A cleaner way of doing the same thing but in a more generic way is by using the formatter arg:

    p1 <- ggplot(data1) +
        aes(x=x, y=y, colour=x) +
        geom_line() + 
        scale_y_continuous(formatter = function(x) format(x, width = 5))
    

    Do the same for your second plot and make sure to set the width >= the widest number you expect across both plots.

提交回复
热议问题