patchwork
patchwork copied to clipboard
Is it possible to incorporate externally generated figures?
Hi,
Is there a way to incorporate externally generated figures while composing layouts with this package?
Thanks, Minita
You can draw pictures to a ggplot with e.g. cowplot::draw_image()
.
This is more a question of how to draw pictures to a ggplot
, but here is an example:
library(ggplot2)
library(patchwork)
p = ggplot(data = mtcars, aes(x = hp, y = disp)) +
geom_point()
img = ggplot() +
cowplot::draw_image("https://cran.r-project.org/Rlogo.svg")
p + img
Thanks, that makes sense. Thanks for sharing an example!
Hi @mhovd , thanks for the solution. Do you know if there is a way to reduce or eliminate the gray padding around the svg
object?
You can add a raster image directly with patchwork, treating it as any other plot object
library(ggplot2)
library(patchwork)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork')
logo <- png::readPNG(logo, native = TRUE)
p1 + logo
Created on 2023-08-08 by the reprex package (v2.0.1)