How can I remove border lines when using geom_sf?

Sam picture Sam · Dec 8, 2017 · Viewed 7.1k times · Source

I tried doing the following:

ggplot(geography) + geom_sf(aes(fill=rate, color = NULL))

but that didn't get rid of the border lines.

Answer

Peter picture Peter · Dec 8, 2017

Without a reproducible example it is difficult to know exactly what you are looking for. However, I will take a guess that your are looking for a way to suppress the lines marking boundaries between different polygons (regions), e.g., suppress the lines showing country borders on a map of the world. If that is so then here is a solution.

Use lwd = 0 in the geom_sf call.

Example (you might need to download the developmental version of 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")

enter image description here