我正在使用用于创建静态地图的代码来包含在闪亮的应用程序中。但我有一个问题,绘图大小比实际绘图大得多,因此布局看起来不正常。有什么办法可以减少绘图外部的空白吗?
如果可能的话,我希望输出只是情节本身。
# reprex
library(terra)
library(sf)
library(magrittr)
library(ggplot2)
lux <- vect(system.file("ex/lux.shp", package = "terra"))
p <- lux %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill = NAME_2), colour = "white", size = 0.2) +
theme(legend.position = "None") +
# found online - removes the whitespace around the plot but not the external whitespace
theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))
p
Run Code Online (Sandbox Code Playgroud)