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

No side effect from plot_grid when used inside a function returning an object #185

Open
rivorand opened this issue May 2, 2022 · 0 comments

Comments

@rivorand
Copy link

rivorand commented May 2, 2022

Hello.

I'd like to have a base graphics version alongside a ggplot2 version of a plot inside a function which returns some other object.

The issue is the return statement makes plot_grid produce no output at all (inside RStudio plot pane at least).
If one gets rid of this statement, the plots do appear.

require(gridGraphics)
#> Loading required package: gridGraphics
#> Loading required package: grid
require(cowplot)
#> Loading required package: cowplot
require(ggplot2)
#> Loading required package: ggplot2

buggy_fun <- function() {
  ## Graphics
  ### base

  base.g <- ~ {
    plot(0:1, 0:1)
  }

  ### ggplot2
  ggplot.g <- ggplot() +
    geom_rect(aes(xmin= 0, xmax= 1, ymin = 0, ymax= 2), fill="green")

  plot_grid(base.g, ggplot.g, nrow=2)

  return(2) ## No side effect when something is returned from function
}

Created on 2022-05-02 by the reprex package (v2.0.1)

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

1 participant