加拿大R省的map_数据

加拿大R省的map_数据,r,ggplot2,maps,R,Ggplot2,Maps,我正在使用ggplot2绘制美国和加拿大的地图,我想显示美国各州和加拿大各省的轮廓。我能够在geom_polygon()函数中使用map_数据(“state”)勾勒出美国各州的轮廓,但得到一个错误,即map_数据(“省”)或map_数据(“加拿大”)或与加拿大相关的任何内容不是maps中的导出对象 附上的照片是我目前的输出-我希望它看起来完全一样,但与加拿大省的轮廓。我现在的代码如下 library(ggplot2) library(sf) library(rnaturalearth) libr

我正在使用ggplot2绘制美国和加拿大的地图,我想显示美国各州和加拿大各省的轮廓。我能够在geom_polygon()函数中使用map_数据(“state”)勾勒出美国各州的轮廓,但得到一个错误,即map_数据(“省”)或map_数据(“加拿大”)或与加拿大相关的任何内容不是maps中的导出对象

附上的照片是我目前的输出-我希望它看起来完全一样,但与加拿大省的轮廓。我现在的代码如下

library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
library(raster)

#State/Province outlines
states <- map_data("state")
provinces <- map_data("province")

ggplot(data = world) + 
  geom_sf() +
  xlab("Longitude") +
  ylab("Latitude") +
  geom_polygon(data = states, aes(x = long, y = lat, group = group), color = "black", fill = "antiquewhite") +
  coord_sf(xlim = c(-130, -65), ylim = c(25,58.5), expand = FALSE) + 
  annotate(geom = "text", x = -100, y = 40, label = "United States", fontface = "italic", color = "grey22", size = 3) +
  annotate(geom = "text", x = -100, y = 52.5, label = "Canada", fontface = "italic", color = "grey22", size = 3) +
  theme(panel.grid.major = element_line(color = gray(.5), linetype = "dashed", size = 0.5), 
        panel.background = element_rect(fill = "paleturquoise1"))
库(ggplot2)
图书馆(sf)
图书馆(rnaturalearth)
图书馆(RNATuralLearthData)
图书馆(rgeos)
图书馆(光栅)
#州/省概述
州地图包(包含“州”地图)没有加拿大对应的地图。但从不同的来源检索这样的地图相对容易。我看你已经加载了rnaturalearth,所以你可以试试

state_prov <- rnaturalearth::ne_states(c("united states of america", "canada"))
state\u prov-Related:您是否尝试了
map\u数据(“世界”、“加拿大”)
?从这里:也从这里:和这里:
library(raster)
states <- getData(country="USA", level=1)
provinces <- getData(country="Canada", level=1)