如何使用ggplot2在地图上添加经线和纬度线? [英] How to add lines of longitude and latitude on a map using ggplot2?

查看:1291
本文介绍了如何使用ggplot2在地图上添加经线和纬度线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用 ggplot2 绘制加拿大地图。由于默认投影方法是aea(Albers Equal Area),所以经度和纬度在地图上是直线。我想知道如何在地图上以110W,100W,90W和50N,60N,70N的形式显示经纬度。他们应该是曲线。



arcgis shap文件从

  library(ggplot2)
library(rgdal)
countries< -readOGR(Canada.shp,layer =加拿大)
ggplot()+ geom_polygon(data = countries,aes(x = long,y = lat,group = group),fill ='white',color =black)

最终结果应该是这样的。

解决方案

$ c> coord_map ggplot的参数


I am now plotting the map of Canada using ggplot2. Because the default projection method is "aea"(Albers Equal Area), so the longitude and latitude are straight lines on the map. I wonder how I can display the longitude and latitude in the form of "110W, 100W, 90W" and "50N, 60N, 70N" on the map. They should be curves. Thanks a lot.

The arcgis shapfile is downloaded from https://www.arcgis.com/home/item.html?id=dcbcdf86939548af81efbd2d732336db

library(ggplot2)
library(rgdal)
countries<-readOGR("Canada.shp", layer="Canada")
ggplot()+geom_polygon(data=countries,aes(x=long,y=lat,group=group),fill='white',color = "black")

The final result should be like this.

解决方案

You can do this with the coord_map argument of ggplot documented here

This uses projections to alter the coordinate grid. Curved lines would include equal-distance projections, but you should look here for a list of all projections allowed. Which one you choose is a manner of preference.

Using azequidistant (I think this is the Azimuthal equidistant projection), and adding labels manually:

axis_labels <- rbind(
                  data.frame(long = rep(-140,5),lat = seq(40,80,10), labels = seq(40,80,10)), # x axis labels
                  data.frame(long = seq(-140,-60,40),lat = rep(85,3), labels = seq(140,60,-40))  # y axis labels
)

   ggplot() +
  geom_polygon(data=countries,aes(x=long,y=lat,group=group),fill='white',color = "black") + 
  coord_map("azequidistant") +
  scale_x_continuous(breaks = seq(-140,60, by = 20))+
  scale_y_continuous(breaks = seq(40,80, by = 10)) +
  geom_text(data = axis_labels, aes(x = long, y = lat, label = labels)) +
  theme_bw() +
  theme(panel.grid.major = element_line(colour = "grey"),
        panel.border = element_blank(),
        axis.text = element_blank())

这篇关于如何使用ggplot2在地图上添加经线和纬度线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆