Is there a way to remove the ample white space around choropleth maps without saving the plot? (Because when I save the plot, I can resize the resulting picture.) @Spacedman: I aim to get a graphic in a Quarto book publishing with bookdown.org.
nc = sf::st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
ggplot2::ggplot(nc) +
ggplot2::geom_sf(ggplot2::aes(fill = SID79))

Created on 2024-12-19 with reprex v2.1.1
I learned from a StackOverflow answer, that one could resize the window to remove whitespace. But the code for doing this is missing. I tried it with negative parameters in the plot.margin line but failed. I also failed with tips from another SO post.
@Allan-Cameron: I do not know what it means to resize the window. I aim to get a graphic where the plot starts immediately after the last line of text (with only one line of space between text and graphic) and where the text after the plot begins immediately (again with only one line of space to the picture).
With other ggplot2 graphics, I did not encounter this problem of ample white space at the top and bottom of a graphic. This happens only when I use the ggplot2::geom_sf() function.
geom_sfis going to use an aspect ratio that's appropriate for the CRS of your geography. That's a constraint that doesn't exist for nonspatial charts. But Quarto isn't going to set the figure size for you---either you do that through defaults or specify for this image. That's why you end up with blank space to fill that gapfig-height: 3to 3 inches, and the space disappeared. How easy! I am ashamed that I did not know/try to change the figure size.