Draw border around certain rows using cowplot and ggplot2

后端 未结 1 630
说谎
说谎 2021-01-18 05:22

I want to somehow indicate that certain rows in a multipanel figure should be compared together. For example, I want to make this plot:

Look like this plot

相关标签:
1条回答
  • 2021-01-18 05:37

    Since the result of plot_grid() is a ggplot object, one way to do this is to use nested plot grids: one plot_grid() for each row, with the appropriate border added via theme().

    plot_grid(
      # row 1
      plot_grid(plot.mpg, plot.diamonds, nrow = 1, labels = c('A', 'B')) +
        theme(plot.background = element_rect(color = "black")),
    
      # row 2
      plot_grid(plot.mpg2, plot.diamonds2, nrow = 1, labels = c('C', 'D')) +
        theme(plot.background = element_rect(color = "black")), 
    
      nrow = 2)
    

    0 讨论(0)
提交回复
热议问题