Eliminate Outer Margin (Ggplot2 / geom_sf)

Hello there!

I have been wondering if it would be possible to avoid that Ggplot2 includes this outer margin (white space beyond black box around the plot area [aka plot margin, I reckon]). Below is my code and I can control the plot margin well, but I have tried different approaches to reduce the outer margin and nothing has worked so far.

I also would like to clarify that I am aware that I could control it through the width and height options when doing the ggsave. However, I would like to use something like:

grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))

define_region <- function(row, col){
  viewport(layout.pos.row = row, layout.pos.col = col)
}

print(Map1, vp = define_region(1, 1:2)) +
print(Map2, vp = define_region(2, 1)) +
print(Map3, vp = define_region(2, 2))

So I would like to get rid of these white spaces before the saving process.

Many thanks in advance, George.

ggplot() + 
  geom_sf(data = FRO, fill = "#fff5f0", color = "black") +
  geom_sf(data = Coords_FRO_sf, aes(fill = Class_Article), size = 5, alpha = 0.9, show.legend = "point", shape = 21, colour = "black") +
  coord_sf(xlim = c(-8, -5.75), ylim = c(61.35, 62.45)) +
  geom_label_repel(data = Coords_FRO, colour = "black",
                   size = 4.5, force = 3,
                   nudge_x = 0.05, nudge_y = 0.075, segment.curvature = 1,
                   fontface = "bold",
                   aes(x = Longitude, y = Latitude, label = Location, fill = Class_Article, family = "Helvetica"), show.legend = FALSE) +
  annotation_north_arrow(location = "br", which_north = "false", style = north_arrow_fancy_orienteering,
                         pad_x = unit(0.25, "in"), pad_y = unit(0.25, "in")) +
  annotation_scale(location = 'br', line_width = 2, text_cex = 1.35, style = "ticks") +
  theme(panel.background = element_rect(fill = "#f7fbff"),
        panel.border = element_rect(colour = "black", size = 0.5, fill = NA),
        panel.grid.major = element_line(color = "#d9d9d9", linetype = "dashed", size = 0.00005),
        plot.background = element_rect(fill="transparent"),
        panel.margin = unit(c(4, 4, 4 , 4), "cm"), complete = TRUE) +
  guides(color = "none", fill = "none") +
  theme(axis.text.x = element_text(color = "black", size = 13, family = "Helvetica"),
        axis.text.y = element_text(color = "black", size = 13, family = "Helvetica"),
        axis.title = element_blank()) +
  theme(axis.ticks = element_line(color ="black", size = 0.5))

ggsave(file = "FO.jpg", width = 26, height = 16, scale = 0.65, limitsize = FALSE, dpi = 300)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.