ggplot2 - Use an image as area fill in an R plot -


how can graph similar (the dollar image graph)? or packages can with? have (gg)plot using geom_area.

dollar graph image

dollar graph image

this purely novelty purposes, right?

in code below, cover portion of dollar bill above blue curve using geom_ribbon.

library(jpeg) library(grid) library(ggplot2) library(scales) theme_set(theme_classic())  # load image of dollar bill , convert raster grob download.file("https://2marks.files.wordpress.com/2013/07/george-washington-on-one-dollar-bill.jpg",                "dollar_bill.jpg") db = readjpeg("dollar_bill.jpg") db = rastergrob(db, interpolate=true)   # fake data set.seed(3) dat = data.frame(x=1913:2009) dat$y2 = seq(5,950, length=nrow(dat)) + rnorm(nrow(dat), 0, 5) dat$y1 = seq(100,5,length=nrow(dat)) + c(0, -0.5, rnorm(nrow(dat) - 2, 0, 2))  ggplot(dat, aes(x, y1)) +   annotation_custom(db, xmin=1913, xmax=2009, ymin=0, ymax=100) +   geom_ribbon(aes(ymin=y1, ymax=100), fill="white") +   geom_line(size=1, colour="blue") +   geom_line(aes(y=y2/10), size=1, colour="red") +   coord_fixed(ratio=1/2.5) +   scale_y_continuous(limits=c(0,100), expand=c(0,0),                      sec.axis=sec_axis(~.*10, name="currency in circulation\n(billions)", labels=dollar)) +   scale_x_continuous(limits=c(1913,2009), expand=c(0,0)) +   labs(x="", y="purchasing power\n(1913=100)") +   theme(axis.text.y.right=element_text(colour="red"),         axis.title.y.right=element_text(colour="red"),         axis.text.y=element_text(colour="blue"),         axis.title.y=element_text(colour="blue"),         axis.title.x=element_blank()) 

enter image description here


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -