Is there a way to remove the border around labels made with geom_sf_text?

Viewed 1613

I am following the examples here: https://ggplot2.tidyverse.org/reference/ggsf.html to make maps with sf and I'm wondering how to remove the boxes surrounding text labels made with a geom_sf_text call?

2 Answers

Use geom_sf_label includes the white boxes, using geom_sf_text removes the boxes and just prints text:

library(ggplot2)
ggplot(nc_3857[1:3, ]) +
  geom_sf(aes(fill = AREA)) +
  geom_sf_label(aes(label = NAME))

ggplot(nc_3857[1:3, ]) +
  geom_sf(aes(fill = AREA)) +
  geom_sf_text(aes(label = NAME), colour = "white")

Created on 2020-12-01 by the reprex package (v0.3.0)

In addition to @Andrew Baxter, I prefer:

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))

library(ggplot2)
ggplot(nc[1:3, ]) +
geom_sf(aes(fill = AREA)) +
geom_sf_label(aes(label = NAME), label.size  = NA, alpha = 0.5)

It will give label a transparent background.

Related