Remove x and y from geom_sf_text

58 Views Asked by At

Borrowing from https://r-charts.com/spatial/maps-ggplot2/, I want to plot an object using ggplot2 and label them using geom_sf_text. I can plot and adjust settings just fine, but can't determine a way to remove the 'x' and 'y' axis labels.

So, the data is:

map <- read_sf("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.geojson")

And the map is:

ggplot(map) +
  geom_sf(color = "white", aes(fill = unemp_rate)) +
  theme(legend.position = "none", panel.grid=element_blank(), axis.text = element_blank(), axis.ticks = element_blank()) +
  geom_sf_text(aes(label = name)) 

With the resulting map: enter image description here

Removing the geom_sf_text row results in no axis labels, but every time I add that line the labels return. I've tried all the theme and aes commands I can think of, but nothing has worked.

1

There are 1 best solutions below

1
TarJae On BEST ANSWER

In addition to @stefan mentioned possibilities:

using theme_void

ggplot(map) +
  geom_sf(color = "white", aes(fill = unemp_rate)) +
  geom_sf_text(aes(label = name)) +
  theme_void()+
  theme(legend.position = "none", 
        panel.grid=element_blank(), 
        axis.text = element_blank(), 
        axis.ticks = element_blank())

enter image description here

using axis.title.x = element_blank() ``axis.title.y = element_blank()`

ggplot(map) +
  geom_sf(color = "white", aes(fill = unemp_rate)) +
  theme(legend.position = "none", 
        panel.grid=element_blank(), 
        axis.text = element_blank(), 
        axis.ticks = element_blank(),
        axis.title.x = element_blank(),  
        axis.title.y = element_blank())+
  geom_sf_text(aes(label = name)) 

enter image description here

using labs(y = "", x = "")

ggplot(map) +
  geom_sf(color = "white", aes(fill = unemp_rate)) +
  theme(legend.position = "none", 
        panel.grid=element_blank(), 
        axis.text = element_blank(), 
        axis.ticks = element_blank())+
  geom_sf_text(aes(label = name)) +
  labs(y = "", x = "")

enter image description here