How to add texture to fill colors in ggplot2

前端 未结 8 1364
误落风尘
误落风尘 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:17

    You can use ggtextures package by @claus wilke to draw textured rectangles and bars with ggplot2.

    # Image/pattern randomly selected from README
    path_image <- "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks2-256.jpg"
    
    library(ggplot2)
    # devtools::install_github("clauswilke/ggtextures")
    ggplot(mtcars, aes(cyl, mpg)) + 
      ggtextures::geom_textured_bar(stat = "identity", image = path_image)
    

    You can also combine it with other geoms:

    data_raw <- data.frame(x = round(rbinom(1000, 50, 0.1)))
    ggplot(data_raw, aes(x)) +
      geom_textured_bar(
        aes(y = ..prop..), image = path_image
      ) +
      geom_density()
    

提交回复
热议问题