patchwork
patchwork copied to clipboard
patchwork approach to wrap_element(~plot()) does not convert to ggsave
I have applied with success the suggestion
old_par <- [par](https://rdrr.io/r/graphics/par.html)(mar = [c](https://rdrr.io/r/base/c.html)(0, 0, 0, 0), mgp = [c](https://rdrr.io/r/base/c.html)(1, 0.25, 0),
bg = NA, cex.axis = 0.75, las = 1, tcl = -0.25)
p1 +
[wrap_elements](https://patchwork.data-imaginist.com/reference/wrap_elements.html)(panel = ~[plot](https://rdrr.io/r/graphics/plot.default.html)(mtcars$mpg, mtcars$disp), clip = FALSE) +
[ggtitle](https://ggplot2.tidyverse.org/reference/labs.html)('Plot 2') +
[theme](https://ggplot2.tidyverse.org/reference/theme.html)(plot.margin = [margin](https://ggplot2.tidyverse.org/reference/element.html)(5.5, 5.5, 5.5, 35))
[par](https://rdrr.io/r/graphics/par.html)(old_par)
at https://patchwork.data-imaginist.com/articles/guides/assembly.html
However, when I save the plot as
ggsave(
"dev/figures_article/multilevel_intercept_model.pdf",
plot = p,
units = c("mm"),
width = 183 ,
height = 230 ,
limitsize = FALSE
)
I get error
Error in plot.new() : figure margins too large
Because the par
call gets ignored by ggsave.
You can reproduce the behaviour applying the trick and the use ggsave, to observe that there 2 plots produced are different.
How can I use your formatting of a non-ggplot using the par
trick and using ggsave.