How to fill column charts with hachuras using ggplot2

Asked

Viewed 307 times

9

I would like to present column charts using the ggplot2, but I would like them to be filled with hachuras. Because it facilitates the understanding in case of photocopy in black and white!

Exemplo de preenchimento com hachuras (linhas pontilhadas)

Using the base date cars and the command below as an example, as would be?

library(ggplot2)
data(cars)
g <- ggplot(mpg, aes(class))
g + geom_bar()
  • What would be a padding with hachuras?

1 answer

8

Use the package ggtextures, available at 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")

inserir a descrição da imagem aqui

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

  • 1

    Thanks for the good will, but I couldn’t install the package!!! even using your instructions: devtools::install_github("clauswilke/ggtextures")

    1. Install the package devtools first: install.packages("devtools") 2) Run the command I gave you again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.