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

Image grobs aren't treated like normal patches in some cases #221

Closed
mattwarkentin opened this issue Dec 2, 2020 · 2 comments
Closed

Image grobs aren't treated like normal patches in some cases #221

mattwarkentin opened this issue Dec 2, 2020 · 2 comments

Comments

@mattwarkentin
Copy link

Hi Thomas,

Not sure if this is a bug or just a feature not yet implemented (or I'm just doing something wrong), but it seems like images cannot be treated just like ggplot objects for composing patchworks. For the two examples that fail below, they work if logo is replaced with p1, a ggplot object.

library(magrittr)
library(ggplot2)
library(patchwork)

p1 <- 
  mtcars %>% 
  ggplot(aes(mpg, hp)) +
  geom_point() + 
  theme_light()

logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork')
logo <- png::readPNG(logo, native = TRUE)

(p1 / p1) / logo

(p1 / p1) | logo
#> Error: Only knows how to fold ggplot objects together

(p1 | p1) / logo
#> Error: Only knows how to fold ggplot objects together
@Evanleen
Copy link

Along these same lines. Using this same example an error is thrown when logo is the first in the list:
`
library(magrittr)
library(ggplot2)
library(patchwork)

p1 <-
mtcars %>%
ggplot(aes(mpg, hp)) +
geom_point() +
theme_light()

logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork')
logo <- png::readPNG(logo, native = TRUE)

logo / p1 / p1

Error in e1 + e2 + plot_layout(ncol = 1) :
non-numeric argument to binary operator
`
Is there a way to circumvent this?

@Evanleen
Copy link

Along these same lines. Using this same example an error is thrown when logo is the first in the list:
`
library(magrittr)
library(ggplot2)
library(patchwork)

p1 <-
mtcars %>%
ggplot(aes(mpg, hp)) +
geom_point() +
theme_light()

logo <- system.file('help', 'figures', 'logo.png', package = 'patchwork')
logo <- png::readPNG(logo, native = TRUE)

logo / p1 / p1

Error in e1 + e2 + plot_layout(ncol = 1) :
non-numeric argument to binary operator
`
Is there a way to circumvent this?

EDIT: I found the solution

wrap_elements(logo) | p1 | p1

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

2 participants