I am trying to trim the white space from a ggplot map plot that was created using geom_sf()
. I have found multiple resources discussing removing white space when saving a plot using ggsave()
. I am hoping to remove the white space without having to save it, though.
Removing white space using ggsave()
- R ggplot, remove white margins in ggsave/ggplot
Please find below a reproducible example:
library(spData); library(sf); library(ggplot2)
library(cowplot)
data("us_states", package = "spData")
north_carolina = read_sf(system.file("shape/nc.shp", package = "sf"))
nc_plot <- ggplot() + geom_sf(data = north_carolina)
Now, I want nc_plot
to appear at the very bottom left hand corner of a ggdraw()
plot. The coordinates of a ggdraw()
plot start from the bottom left. So, x = 0, y = 0 should be the bottom left.
ggdraw() + draw_plot(nc_plot, x = 0, y = 0)
As you can see, though, the plot is all the way left but not all the way at the bottom. This is because there is white space above and below the plot. I want to remove the white space from the plot so that I can have the map at the bottom left.