Setting different axis limits for each facet in ggplot2 not using scales = “free”

前端 未结 1 484
轮回少年
轮回少年 2020-12-21 12:15

The general solution that I would like is to be able to specify arbitrary axis limits for each facet independently.

Basic functionality is obtained by setting the sc

相关标签:
1条回答
  • 2020-12-21 13:08

    Before this is closed, I think it is important to expand the suggestion by @Axeman : this may not be possible with facet_wrap directly, but the behavior can be achieved by chunking the groups you want and stitching them together with cowplot. Here, I separated into "low" and "high" quality, but the grouping is arbitrary and could be whatever you wanted. Likely want to mess with the style a bit, but the default from cowplot is acceptable for this purpose:

    library(cowplot)
    
    lowQ <- 
      ggplot(diamonds %>%
               filter(as.numeric(clarity) <= 4)
             , aes(x = carat
                   , y = price)) +
      geom_point() +
      facet_wrap(~clarity
                 , nrow = 1)  
    
    
    hiQ <- 
      ggplot(diamonds %>%
               filter(as.numeric(clarity) > 4)
             , aes(x = carat
                   , y = price)) +
      geom_point() +
      facet_wrap(~clarity
                 , nrow = 1)
    
    plot_grid(lowQ, hiQ, nrow = 2)
    

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