Skip to content

Instantly share code, notes, and snippets.

@trinker
Created October 4, 2018 12:38
Show Gist options
  • Save trinker/174bb3bc3abb80261582924d4e2472cd to your computer and use it in GitHub Desktop.
Save trinker/174bb3bc3abb80261582924d4e2472cd to your computer and use it in GitHub Desktop.
Plot images as points
if (!require("pacman")) install.packages("pacman")
pacman::p_load(ggimage)
presidential_icons <- data.frame(
x = c(15, 30),
y = c(2.5, 4.5),
name = c('trump', 'obama'),
image = c(
'http://www.stickpng.com/assets/images/5841c17aa6515b1e0ad75aa1.png',
'http://www.stickpng.com/assets/images/580b57fbd9996e24bc43be4e.png'
),
size = c(.15, .2)
)
ggplot2::ggplot(mtcars, aes(mpg, wt)) +
ggplot2::geom_point(aes(color = cyl)) +
ggimage::geom_image(data = presidential_icons, aes(x = x, y = y, image = image, size = size)) +
scale_size(range = c(.15, .2))
@trinker
Copy link
Author

trinker commented Oct 4, 2018

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment