0

One guy just told me about using the function ggdraw to overlap two figure.

When I saved the output using ggsave, the margin of both side (left, right) of my picture was shrank. I did use its arguments, but nothing happened.

Does anyone know about setting up the margin when using this function ggdraw?

updated

I would like to add the output that I got by using this code (it is a clip since I want you to see it clearly)

p1 <- cowplot::ggdraw(p) + cowplot::draw_plot(legend, x = .18, y = .25, width = 0.5, height = .5)

ggsave(plot = p1, filename = "outputs/tree_test.png",
         width = 45, height = 30, units = "cm", dpi = 300)

You guys can see that my margin of both sides has gone!.

enter image description here

Anh
  • 735
  • 2
  • 11
  • 2
    I'm pretty sure `ggsave` allows you to set the `width=` and `height=`, so you can control the ratio yourself. – r2evans Oct 25 '21 at 14:21
  • yes, I did use `width` and `height` from `ggsave`, but it was still different between the picture with/without using `ggdraw` function – Anh Oct 25 '21 at 14:24
  • like the output I got, two margin of both sides, somehow, disappeared – Anh Oct 25 '21 at 14:26
  • Okay. It works for me, perhaps you should edit your question to make it [reproducible](https://stackoverflow.com/q/5963269) so that the rest of us can see what you're talking about. As it stands, this question is purely hypothetical without something concrete, typically a requirement or really-nice-to-have on StackOverflow. – r2evans Oct 25 '21 at 14:27
  • yess thank you about this. I will edit now – Anh Oct 25 '21 at 14:31

1 Answers1

0

It seems there is a save_plot function that is adapted for ggdraw objects. https://wilkelab.org/cowplot/articles/drawing_with_on_plots.html

Kene David Nwosu
  • 828
  • 6
  • 12