0

I am working on making a map of North America. When I plot the map, the longitude axis labels show up as they are supposed to but for some unknown reason, the latitude axis labels do not show. How can I get the latitude axis labels to show?

library(ggplot2)
library(ggspatial)
library(dplyr)
library(geodata)
library(sf)
library(tidyr)
library(lubridate)

# Country shapefiles for North America ----
can <- gadm(country = 'CAN', level = 0, path=tempdir()) %>%
  st_as_sf()
usa <- gadm(country = 'USA', level = 0, path=tempdir()) %>%
  st_as_sf()
mex <- gadm(country = 'MEX', level = 0, path=tempdir()) %>%
  st_as_sf()

# Shapes of countries near North America ----
cc <- country_codes()
cca <- cc %>%
  filter(UNREGION1 %in% c('Caribbean','Central America'))
cca <- cca$ISO3
cca <- gadm(country = cca, level = 0, path=tempdir()) %>%
  st_as_sf()
green <- gadm(country = 'GRL', level = 0, path=tempdir()) %>%
  st_as_sf()
rus <- gadm(country = 'RUS', level = 0, path=tempdir()) %>%
  st_as_sf()

# Map of North America ----
ggplot() +
  geom_sf(data = green,
          mapping = aes(geometry = geometry),
          color = "black") +
  geom_sf(data = rus,
          mapping = aes(geometry = geometry),
          color = "black") +
  geom_sf(data = can,
          mapping = aes(geometry = geometry),
          color = "black") +
  geom_sf(data = usa,
          mapping = aes(geometry = geometry),
          color = "black") +
  geom_sf(data = cca,
          mapping = aes(geometry = geometry),
          color = "black") +
  geom_sf(data = mex,
          mapping = aes(geometry = geometry),
          color = "black") +
  coord_sf(xlim = c(-180, -48), ylim = c(12, 84), expand = F) +
  annotation_scale(location = "bl",
                   width_hint = 0.2,
                   text_cex = 1) +
  annotation_north_arrow(location = "bl",
                         which_north = "true",
                         pad_x = unit(0.15, "in"),
                         pad_y = unit(0.3, "in"),
                         style = north_arrow_fancy_orienteering) +
  theme_bw() +
  theme(plot.margin = grid::unit(c(0,2,0,2), "mm"),
        text = element_text(size = 16),
        axis.text.x = element_text(size = 14, color = "black"),
        axis.text.y = element_text(size = 14, color = "black"),
        panel.grid.major = element_blank(),
        panel.background = element_rect(fill = "lightblue"))

Map produced from code above: enter image description here

mfg3z0
  • 561
  • 16
tassones
  • 891
  • 5
  • 18
  • 4
    That's not exactly a **minimal** reproducible example ;-) Anyhow, try limiting the western map extent to somewhat less than the full -180°, e. g.: `... + coord_sf(xlim = c(-170, -48), ylim = c(12, 84)) + ...` – I_O May 26 '23 at 15:29
  • @I_O, interesting, any insights on why it behaves like this? – margusl May 26 '23 at 17:09
  • 1
    @margusl: not yet. What tipped me off was the theme's `plot.margin` specification. When increasing the left margin didn't help, I started stripping the plot components, working from the bottom up. I hardly use `coord_sf` as `geom_sf` usually gets thing right on its own, – I_O May 26 '23 at 18:53

0 Answers0