I'm looking to create a map of Newfoundland and Labrador, Canada using ggplot with GADM data. This is my code:
library(ggplot2)
library(raster)
Province <- getData("GADM", country="CAN", level=1)
NL <- (Province[Province$NAME_1=="Newfoundland and Labrador"])
map <- ggplot() +
geom_polygon(data=NL, aes(long, lat, group=group), colour="azure4", fill="cadetblue1") +
coord_map()
map
For some reason, it's showing me the entire map of Canada and not just the province of Newfoundland. Any idea why this is? Thanks in advance!
NL
? I think you'll need to use:Province[Province$NAME_1=="Newfoundland and Labrador", ])
. When referencing the data frame, with brackets, it'sdf[rows, columns]
. You are looking to define the rows based onNAME_1
, but want all columns, so you need the comma.