1

How can I remove axis line and add labels next to grids in a projected map plot created in ggplot2? I want to produce a map similar to this one:

this

Here is my reproducible example code:

adf <- structure(
  list(long = c(249.999938964844, 152.500122070312, 152.500122070312, 
                249.999938964844, 249.999938964844), 
       lat = c(12.5000610351562, 12.5000610351562, 80, 80, 12.5000610351562), 
       order = 1:5, 
       hole = c(FALSE,FALSE, FALSE, FALSE, FALSE),
       piece = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "1", class = "factor"),
       id = c("0", "0", "0","0", "0"), 
       group = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "0.1", class = "factor"), 
       longg = c(251, 151, 151, 251, 251), 
       latt = c(11, 11, 81, 81, 11)), 
  .Names = c("long", "lat", "order", "hole", "piece", "id", "group", "longg", "latt"), 
  row.names = c(NA, -5L), 
  class = "data.frame")    
adf

projplt <- ggplot() +
  geom_path(data = adf, 
            aes(x = longg, y = latt, group = group), 
            colour = "Black", alpha = 1,size = 1.5) +
  scale_x_continuous(limits = c(150.5, 252.0),
                     breaks = c(155, 170, 185, 200, 215, 230, 245, 260, 275),
                     labels = c("155°E", "170°E","175°W", "160°W", "145°W", 
                                "130°W","115°W", "100°W", "85°W"),
                     expand = c(0,0))+
  scale_y_continuous(limits = c(10.5, 81.5),
                     breaks = c(10, 25, 40, 55, 70),
                     labels = c("10°N", "25°N", "40°N", "55°N", "70°N"),
                     expand = c(0, 0))+
  coord_map(projection = "albers", lat0 = 45, lat1 = 50)
projplt
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Lily Nature
  • 613
  • 7
  • 18
  • If all you want is the shape, you need to set axis labels (and ticks?) to `element_blank()` in the `theme()`. See here: https://stackoverflow.com/questions/35090883/remove-all-of-x-axis-labels-in-ggplot – cparmstrong Mar 28 '18 at 17:18
  • At which position you want to add labels? – pogibas Mar 28 '18 at 21:00
  • next to major grid lines i.e. at the end of grid lines like in the attached figure when each labels are next to grid lines.. – Lily Nature Mar 28 '18 at 21:15

1 Answers1

0

You can add the labels at your desired locations using annotate(). Hiding the original labels can be done with theme(XXX = element_blank()), as seeellayewhy pointed out.

ggplot() +
  geom_path(data = adf, 
            aes(x = longg, y = latt, group = group), 
            colour = "Black", alpha = 1,size = 1.5) +

  # longitude
  annotate("text",
           x = c(155, 170, 185, 200, 215, 230, 245),
           y = min(adf$latt) - 3,
           label = c("155°E", "170°E","175°W", "160°W", "145°W", "130°W","115°W")) +

  # latitude
  annotate("text",
           x = min(adf$longg) - seq(3, 6),
           y = c(25, 40, 55, 70),
           label = c("25°N", "40°N", "55°N", "70°N")) +

  coord_map(projection = "albers", lat0 = 45, lat1 = 50) +

  # hide original axis labels
  theme(axis.title = element_blank(),
        axis.ticks = element_blank(),
        axis.text = element_blank())

map

Note: The y positions for longitude & x positions for latitude may need to be tweaked, depending on the size of your desired plot. I chose values that looked decent on my screen.

Z.Lin
  • 28,055
  • 6
  • 54
  • 94