How to add texture to fill colors in ggplot2

前端 未结 8 1214
误落风尘
误落风尘 2020-11-22 08:30

I\'m currently using scale_brewer() for fill and these look beautiful in color (on screen and via color printer) but print relatively uniformly as greys when us

8条回答
  •  死守一世寂寞
    2020-11-22 09:05

    It might be useful to create a dummy data frame whose contours correspond to "textures" and then use geom_contour. Here is my example:

    library(ggplot2)
    
    eg = expand.grid(R1 = seq(0,1,by=0.01), R2 = seq(0,1,by=0.01))
         eg$importance = (eg$R1+eg$R2)/2
    
      ggplot(eg , aes(x = R1, y = R2)) +
      geom_raster(aes(fill = importance), interpolate=TRUE) +
      scale_fill_gradient2(low="white", high="gray20", limits=c(0,1)) +
      theme_classic()+
      geom_contour(bins=5,aes(z=importance), color="black", size=0.6)+
      coord_fixed(ratio = 1, xlim=c(0,1),ylim=c(0,1))
    

    And here is the result: shaded plot with lines

    (the lines should be smoothed)

提交回复
热议问题