Need help with ggtextures?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

clauswilke
139 Stars 9 Forks GNU General Public License v2.0 25 Commits 2 Opened issues

Description

Drawing textured rectangles and bars with ggplot

Services available

!
?

Need anything else?

Contributors list

# 32,523
R
HTML
Shell
visuali...
14 commits
# 254,070
R
HTML
Shell
data-vi...
5 commits
# 467,504
R
Emacs
evil
Shell
1 commit
# 752,828
R
1 commit

ggtextures

Written by Claus O. Wilke

This package provides functions to draw textured rectangles and bars with the grid graphics system and with ggplot2.

Note: The package is at the stage of tech demo/proof of concept. It is not ready for production purposes.

Installation

Please install from github via:

devtools::install_github("clauswilke/ggtextures")

Example

Basic example of a textured rectangle drawn with grid:

library(ggtextures)
library(grid)
library(magick)
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11

img

This is a basic example of textured rectangles in ggplot2:

library(ggplot2)
library(tibble)

data

Note that we are reading in the svg file explicitly, using the function

image_read_svg()
from the magick package. This is needed for proper handling of transparencies in svg files.

We can also make a textured equivalent to

geom_col()
or
geom_bar()
:
df 

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)

ggplot(mpg, aes(factor(trans), image = class)) +
  geom_textured_bar() +
  scale_image_manual(values = images)

Isotype bars can be drawn with

geom_isotype_bar()
and
geom_isotype_col()
. The units of the images are set as grid native units. Default is that the image height corresponds to one data unit.
data 

ggplot(data, aes(animal, count, image = image)) +
  geom_isotype_col(
    img_width = grid::unit(1, "native"), img_height = NULL,
    ncol = NA, nrow = 1, hjust = 0, vjust = 0.5, fill = "#80808040"
  ) +
  coord_flip() +
  theme_minimal()

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.