When saving maps as PDF in R, the pdf still stores map data (polygons, polylines) that are in the object being plotted but outside the visible area of the map. Is there any way to prevent that?
library(ggplot2)
library(tidyverse)
continent <- map_data('world') %>%
filter(region %in% c("Canada", "USA")) %>% fortify()
pdf(file = ".../Results/My Plot.pdf", width=8, height=4)
# pdf() or ggsave() give the same results
ggplot()+
geom_polygon(data = continent, aes(x = long, y = lat, group=group),
fill="lightgray", colour = NA) +
coord_sf(xlim = c(-82, -57), ylim = c(28, 43), expand = FALSE)
dev.off()
The map as seen in the pdf
The map in Inkscape, with the main plot "ungrouped" (as in https://inkscape-manuals.readthedocs.io/en/latest/grouping.html - ungrouping the main part of the plot 2 or 3 times).



