如何在ggplot 2中删除地图旁边的轴和移动轴标签以获得投影图

时间:2018-03-28 16:40:50

标签: r ggplot2 spatial

如何在ggplot2中创建的投影地图中删除轴线并在网格旁边添加标签?我想制作一个类似于这个的地图:

this

这是我可重复的示例代码:

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

1 个答案:

答案 0 :(得分:0)

您可以使用annotate()在所需位置添加标签。可以使用theme(XXX = element_blank())来隐藏原始标签,正如seeellayewhy所指出的那样。

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

注意:经度和时间的y位置纬度的x位置可能需要调整,具体取决于所需绘图的大小。我在屏幕上选择了看起来不错的价值。