How to fill column graphics with hachures using ggplot2

8

I would like to display column graphs, using ggplot2 , but would like to fill them with hachures. It makes it easier to understand in case of black and white photocopy!

Using the base date cars and the command below as an example, how would it look?

library(ggplot2)
data(cars)
g <- ggplot(mpg, aes(class))
g + geom_bar()
    
asked by anonymous 03.12.2018 / 14:08

1 answer

8

Use the ggtextures package, available in this link .

devtools::install_github("clauswilke/ggtextures")
library(ggplot2)
library(ggtextures)

images = c(
  compact = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks2-256.jpg",
  midsize = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/stone2-256.jpg",
  suv = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/siding1-256.jpg",
  '2seater' = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/mulch1-256.jpg",
  minivan = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/rocks1-256.jpg",
  pickup = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/wood3-256.jpg",
  subcompact = "http://www.hypergridbusiness.com/wp-content/uploads/2012/12/concrete1-256.jpg"
)

ggplot(mpg, aes(class, image = class)) +
  geom_textured_bar() +
  scale_image_manual(values = images) +
  labs(x="Tipo de Carro", y="Frequência", image="Tipo de Carro")

Now you can choose images with the textures or hachuras that best suit you.

    
03.12.2018 / 16:18