How to add longitude and latitude lines on a map using ggplot2?

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

The arcgis form file is downloaded from https://www.arcgis.com/home/item.html?id=dcbcdf86939548af81efbd2d732336db enter image description here

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 end result should be like this. enter image description here

+4
source share
2 answers

coord_map ggplot

. , . .

azequidistant ( , ) :

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())

enter image description here

+4

graticule, .

graticule NaturalEarthData.

countries<-readOGR("Canada.shp", layer="Canada")
grat <- readOGR("graticule.shp", layer="graticule")

grat_prj <- spTransform(grat, CRS(countries))

ggplot() + 
geom_polygon(data=countries, aes(x=long,y=lat,group=group),fill='white',color = "black") + 
geom_path(data=grat_prj, aes(long, lat, group=group, fill=NULL), linetype="solid", color="grey50")
0

Source: https://habr.com/ru/post/1648819/


All Articles