knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

ggwithimages - Drawing Basic Plots with Images

This package allows you to plot basic plots (currently lines and histograms) using images. You kinda have to see it to get it...

Install:

devtools::install_github("gsimchoni/ggwithimages")

Load:

library(ggwithimages)

Draw a line plot with the Annapurna mountains:

annapurna <- png::readPNG(system.file("extdata", "annapurna.png", package = "ggwithimages"))
sky <- png::readPNG(system.file("extdata", "sky.png", package = "ggwithimages"))
kathmandu_hourly_aqi <- readr::read_csv(system.file("extdata", "kathmandu_hourly_aqi.csv", package = "ggwithimages"))

library(ggplot2)
ggplot(kathmandu_hourly_aqi, aes(hour, aqi)) +
  geom_line_with_image(annapurna, sky) +
  labs(title = "Air Quality Index in the Thamel, Kathmandu, Nepal",
       subtitle = "Measured in PM2.5 by the US Embassy in Kathmandu",
       y = "Hourly Mean AQI [PM2.5]",
       x = "Hour") +
  ylim(c(50, 200)) +
  theme(text = element_text(family="mono"),
        axis.title.x = element_text(size=12),
        axis.title.y = element_text(size=12))

Draw a histogram with NYC buildings:

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) +
  labs(title = "NYC Daily No. of Accidents Distribution",
       subtitle = "Data Obtained on January 3, 2018 from NYC OpenData",
       y = "Frequency",
       x = "Daily No. of Accidents") +
  ylim(c(0, 700)) +
  xlim(c(0, 1300)) +
  theme(text = element_text(family="mono"),
        axis.title.x = element_text(size=12),
        axis.title.y = element_text(size=12))

See more in this blog post.



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