使用 geom_sf 时如何删除边框线?
How can I remove border lines when using geom_sf?
我尝试执行以下操作:
ggplot(geography) + geom_sf(aes(fill=rate, color = NULL))
但这并没有消除边界线。
如果没有可重现的示例,就很难确切地知道您在寻找什么。但是,我猜测您正在寻找一种方法来抑制标记不同多边形(区域)之间边界的线,例如,抑制在世界地图上显示国家边界的线。如果是这样,那么这里有一个解决方案。
在 geom_sf
调用中使用 lwd = 0
。
示例(您可能需要下载ggplot2
的开发版本)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)
library(maps)
library(maptools)
library(rgeos)
library(sf)
world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE))
with_boundary <-
ggplot() +
geom_sf(data = world1, mapping = aes(fill = ID)) +
theme(legend.position = "none") +
ggtitle("With Country Boundaries")
without_boundary <-
ggplot() +
geom_sf(data = world1, mapping = aes(fill = ID), lwd = 0) +
theme(legend.position = "none") +
ggtitle("Without Country Boundaries")
我尝试执行以下操作:
ggplot(geography) + geom_sf(aes(fill=rate, color = NULL))
但这并没有消除边界线。
如果没有可重现的示例,就很难确切地知道您在寻找什么。但是,我猜测您正在寻找一种方法来抑制标记不同多边形(区域)之间边界的线,例如,抑制在世界地图上显示国家边界的线。如果是这样,那么这里有一个解决方案。
在 geom_sf
调用中使用 lwd = 0
。
示例(您可能需要下载ggplot2
的开发版本)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)
library(maps)
library(maptools)
library(rgeos)
library(sf)
world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE))
with_boundary <-
ggplot() +
geom_sf(data = world1, mapping = aes(fill = ID)) +
theme(legend.position = "none") +
ggtitle("With Country Boundaries")
without_boundary <-
ggplot() +
geom_sf(data = world1, mapping = aes(fill = ID), lwd = 0) +
theme(legend.position = "none") +
ggtitle("Without Country Boundaries")