wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
704 stars 84 forks source link

Creating plot grids from image files #84

Closed dhimmel closed 6 years ago

dhimmel commented 6 years ago

I use cowplot::plot_grid to arrange my R plots (made with ggplot2) into a single figure that includes labels. However, oftentimes I'll want to combine one image made in R with an existing image saved to disk (i.e. SVG or PNG).

In short, I want a scripted way to make multi-panel plot where individual panels are labeled and the inputs are image files (preferably vector). Many arguments of cowplot::plot_grid wouldn't apply, such as align, but the general concept of laying out images in a grid seems the same.

Anyways, is it possible to use existing images in a cowplot grid? If not, does anyone have a recommendation over how to combine images into a larger figure that works on SVG inputs?

clauswilke commented 6 years ago

Do the examples at the end of this vignette do what you want?

dhimmel commented 6 years ago

Do the examples at the end of this vignette do what you want?

Ah didn't scroll down far enough! I think cowplot::draw_image is exactly what I want.

Specifically I want to do something like this example (function provenance added by me):

p <- ggplot2::ggplot(iris, aes(x = Sepal.Length, fill = Species)) +  ggplot2::geom_density(alpha = 0.7)
p2 <- cowplot::ggdraw() + cowplot::draw_image("http://jeroen.github.io/images/tiger.svg", scale = 0.9)
cowplot::plot_grid(p, p2, labels = "AUTO")

Will reopen this if I encounter any problems. Thanks for the link!

dhimmel commented 6 years ago

Note cowplot::draw_image was added in v0.9.0.