geom_hist_with_image: Histogram Using Images

Description Usage Arguments Note Examples

Description

This function allows you to draw a simple histogram of a single variable, using one or two images

Usage

1
2
3
4
5
geom_hist_with_image(bottomImg = NULL, topImg = NULL, mapping = NULL,
  data = NULL, stat = "identity", position = "identity", na.rm = FALSE,
  show.legend = NA, inherit.aes = TRUE, bgColor = "white",
  lineColor = 1, lineWidth = 2, lineType = "solid", breaks = "Sturges",
  freq = NULL, ...)

Arguments

bottomImg

The image "inside" the histogram. This should be an image object as obtained by png::readPNG, jpeg::readJPEG, magick::image_read etc. You must specify at least this image.

topImg

The image "outside" the histogram.

bgColor

Background color outside the histogram in case you don't specify topImg, defaults to white.

lineColor

Line color as accepted by R in the col parameter, defaults to black.

lineWidth

Line width as accepted by R in the lwd parameter, defaults to 1.

lineType

Line type as accepted by R in the lty parameter, defaults to "solid".

breaks

See the breaks parameter in ?hist, defaults to "Sturges".

freq

See the freq parameter in ?hist.

...

Other standard ggplot2 parameters such as mapping, data, stat etc.

Note

By default geom_hist_with_image will not add padding in the x and y axes. This default behavior of ggplot2 does not make sense when it comes to plotting with images. You can however override this by adding + xlim(c(0, 100)). Make sure the result is meaningful though.

Examples

1
2
3
4
5
6
7
nyc <- png::readPNG(system.file("extdata", "nyc.png", package = "ggwithimages"))
night_sky <- png::readPNG(system.file("extdata", "night_sky.png", package = "ggwithimages"))
nyc_accidents <- readr::read_csv(system.file("extdata", "nyc_accidents.csv", package = "ggwithimages"))
library(ggplot2)
ggplot(nyc_accidents, aes(n_accidents)) +
  geom_hist_with_image(nyc, night_sky) +
  ylim(c(0, 700))

gsimchoni/ggwithimages documentation built on May 21, 2019, 3:09 a.m.