remargin | R Documentation |
To avoid the overlay rectangles moving around when the plot margins change, you can use this function to set specific margins for your plot. You will probably want to specify a large enough margin so that the axes and legends don't go out of the plot area.
remargin(g, t, r, b, l, unit = "npc")
g |
A |
t , r , b , l |
Top, right, bottom, and left margins to set. |
unit |
Unit for the margins (see |
Note that this only works with ggplot2
plots. For base plots, you can set
the margins using par(plt = c(x1, x2, y1, y2))
. See graphics::par()
for
details.
A ggplot2
plot with margins adjusted.
plot1 = ggplot2::ggplot(data.frame(x = rnorm(10), y = rnorm(10))) +
ggplot2::geom_point(ggplot2::aes(x, y))
plot2 = remargin(plot1, 0.1, 0.1, 0.1, 0.1) # plot with 10% margins all around
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.