Skip to content

Instantly share code, notes, and snippets.

@cwickham
Created July 31, 2014 23:44
Show Gist options
  • Select an option

  • Save cwickham/4b1ec9df3cd711ad683f to your computer and use it in GitHub Desktop.

Select an option

Save cwickham/4b1ec9df3cd711ad683f to your computer and use it in GitHub Desktop.
add a cat
library(httr)
library(ggplot2)
add_cat <- function(width = 400, height = 400){
r <- GET(paste("http://theoldreader.com/kittens", width, height, sep = "/"))
stop_for_status(r)
img <- content(r)
bw <- 0.2989*img[,,1] + 0.5870*img[,,2] + 0.1140*img[,,3]
lighter <- bw + (0.7 * (1-bw))
annotation_raster(lighter, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
}
ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment