Non-linear color distribution over the range of values in a geom_raster

前端 未结 1 1893
不知归路
不知归路 2020-12-13 20:54

I\'m faced with the following problem: a few extreme values are dominating the colorscale of my geom_raster plot. An example is probably more clear (note that t

1条回答
  •  时光说笑
    2020-12-13 21:21

    Seems that ggplot (0.9.2.1) and scales (0.2.2) bring all you need (for your original m):

    library(scales)
    
    qn = quantile(m$fill, c(0.01, 0.99), na.rm = TRUE)
    qn01 <- rescale(c(qn, range(m$fill))) 
    
    ggplot(m, aes(x = x, y = y, fill = fill)) + 
       geom_raster() + 
       scale_fill_gradientn (
          colours = colorRampPalette(c("darkblue", "white", "darkred"))(20),
          values = c(0, seq(qn01[1], qn01[2], length.out = 18), 1)) +
       theme(legend.key.height = unit (4.5, "lines"))
    

    resulting plot

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