I am trying to map lat/lon locations in the Arctic/subarctic region using ggplot2, and colour them by type.
Here are the packages I'm using:
library(ggplot2)
library(rgdal)
library(ggmap)
library(sp)
library(dplyr)
library(ggspatial) #To use geom_sf to add shapefiles
Here is an example of my data:
dat <- data.frame(
"Lat" = c(70.5,74.5,58.5,60.5),
"Lon" = c(-21.5,19.0,-161.5,-147.5),
"Type"=c("A","B","A","B")
)
dat
I created a shapefile for the Arctic circle, found here: https://www.arcgis.com/home/item.html?id=f710b74427a14a1d804e90fbf94baed4
ArcticCircle <- sf::st_read("C:/.../LCC_AC.shp")
I am trying to map this using ggplot2, but I can't find a way to add a basemap with the Lambert Conformal Conic projection.
I know you can use coord_sf() to specify projection and boundaries, but I can't find a code for a conical projection.
p <- ggplot()+
geom_point(data = dat, aes(x = Lon, y = Lat, colour = Type))+
geom_sf(data = ArcticCircle, linetype = "dashed", aes())+
xlab("Longitude")+
ylab("Latitude")+
p
My map boundary would preferably be a circle around the Arctic circle at about 45 degrees latitude. If making a circle boundary isn't possible, a rectangle around that latitude would work as well.
I am relatively new to R, so any help would be appreciated!
there are a few mistakes I found in your code, first of all your dat data frame contains x and y values in string format and is not numeric (which would not help when plotting!).
Secondly, unlike other GIS softwares, R does not do On the fly projection conversion! So using your points with the LAT LONG does not work, with your shapefile, as it is in a different CRS! Here is the ArcticCircle's CRS:
So, what I did was convert your LAT LONG point file to the CRS shown above, and then made the ggplot, I will put all code all together below, with comments:
This is how the plot looks in the end:
Hopefully that helps, let me know if anything is unclear!
EDIT: New code with basemap (Thanks to Majid for the data)