小编dcu*_*e27的帖子

有没有办法删除 ggplot 之外的空白?

我正在使用用于创建静态地图的代码来包含在闪亮的应用程序中。但我有一个问题,绘图大小比实际绘图大得多,因此布局看起来不正常。有什么办法可以减少绘图外部的空白吗?

如果可能的话,我希望输出只是情节本身。

我的意思是空白的绘制不佳的例子

# 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)

r spatial ggplot2 r-sf

7
推荐指数
1
解决办法
2102
查看次数

标签 统计

ggplot2 ×1

r ×1

r-sf ×1

spatial ×1