1

I'm making a map in ggplot, and because I'm using the rnaturalearth package for the world basemap, the tick mark labels have N and W in them.

enter image description here

How do I remove the square box and the N or W symbols in the tick marks? The longitude values should be -0 to -70.

library(tidyverse)
library(rnaturalearth)
world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot() +
  # basemap
  geom_sf(data = world, colour = NA, fill = "grey75") +
  coord_sf(ylim = c(43, 72), xlim = c(-68, -2)) +
  labs(x = "", y = "") +
  theme_bw()
tnt
  • 1,149
  • 14
  • 24
  • 1
    This has nothing to do with rnaturalearth, but with `coord_sf` – tjebo May 01 '23 at 20:55
  • 1
    ah, thanks for that clarification! I had tried making the map without the coord_sf, and still saw the same results, so I assumed it was due to the basemap. – tnt May 01 '23 at 21:39
  • This is because when you use geom_sf, it will use coord_sf by default. (To my knowledge) – tjebo May 01 '23 at 21:45

1 Answers1

3

You could set your desired format for the axes labels via the labels argument of scale_x/y_continuous, e.g. to achieve your desired result use labels = ~ .x:

library(tidyverse)
library(rnaturalearth)

world <- ne_countries(scale = "medium", returnclass = "sf")

ggplot() +
  geom_sf(data = world, colour = NA, fill = "grey75") +
  coord_sf(ylim = c(43, 72), xlim = c(-68, -2)) +
  labs(x = NULL, y = NULL) +
  scale_x_continuous(labels = ~ .x) +
  scale_y_continuous(labels = ~ .x) +
  theme_bw()

stefan
  • 90,330
  • 6
  • 25
  • 51
  • AFK but wouldn’t this possibly be adjustable within coord_sf, https://ggplot2.tidyverse.org/reference/ggsf.html, e.g. with the label_axes argument? – tjebo May 01 '23 at 20:56
  • 2
    Thx @tjebo for pointing me to these arguments. Just had a look. But unfortunately haven't found an option to format the labels via `labels_axis`. – stefan May 01 '23 at 21:13