Free colour scales in facet_grid

前端 未结 1 1684
独厮守ぢ
独厮守ぢ 2021-02-06 04:54

Say I have the following data frame:

# Set seed for RNG
set.seed(33550336)

# Create toy data frame
loc_x <- c(a = 1, b = 2, c = 3)
loc_y <- c(a = 3, b = 2         


        
相关标签:
1条回答
  • 2021-02-06 05:09

    Using the development version of dplyr:

    library(dplyr)
    library(purrr)
    library(ggplot2)
    library(cowplot)
    
    df %>% 
      group_split(variables, season) %>% 
      map(
        ~ggplot(., aes(loc_x, loc_y, color = value)) + 
          geom_point(size = 5) +
          scale_colour_gradient2(
            low = "#3366CC", 
            mid = "white", 
            high = "#FF3300", 
            midpoint = median(.$value)
          ) +
          facet_grid(~ variables + season, labeller = function(x) label_value(x, multi_line = FALSE))
      ) %>% 
      plot_grid(plotlist = ., align = 'hv', ncol = 2)
    

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