Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to incorporate externally generated figures? #283

Closed
shahmj opened this issue Nov 12, 2021 · 6 comments
Closed

Is it possible to incorporate externally generated figures? #283

shahmj opened this issue Nov 12, 2021 · 6 comments

Comments

@shahmj
Copy link

shahmj commented Nov 12, 2021

Hi,

Is there a way to incorporate externally generated figures while composing layouts with this package?

Thanks,
Minita

@mhovd
Copy link

mhovd commented Nov 30, 2021

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

image

@shahmj
Copy link
Author

shahmj commented Nov 30, 2021

Thanks, that makes sense. Thanks for sharing an example!

@rbutleriii
Copy link

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?

@thomasp85
Copy link
Owner

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)

@DanChaltiel
Copy link

For future travelers like myself, note that logo + p1 will not work though.
(Not sure if this is worth a new issue)

@thomasp85
Copy link
Owner

This is already documented in the vignettes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants