如何获取包含区域和子区域的地图 [英] How to obtain maps with regions and subregions
问题描述
我的问题:我想从给定国家/地区获得地图,其中r包含分区.
到目前为止:例如, map
软件包提供了 counties
地图,该数据库可生成根据美国人口普查数据生成的美国大陆各县的地图.例如,提供子区域的 italy
地图(例如一对代码行)可以绘制该区域:
it<-ggplot2 :: map_data("italy")库(ggplot2)ggplot(it,aes(long,lat,group = group))+geom_polygon()+coord_fixed()
我想在其他国家/地区获得相同的地图,但是不幸的是,我认为 maps
包仅提供美国,意大利和法国的此信息.是否有提供此类信息的包装?
基于@alistaire的评论:
library("rnaturalearth")库("ggplot2")西班牙<-ne_states(国家=西班牙",returnclass ="sf")ggplot(数据=西班牙)+geom_sf()
由(v0.2.1)于2019-02-12创建
sup>My problem: I want to obtain a map from a given country with subregions in r.
So far: For example map
package provides counties
map which database produces a map of the counties of the United States mainland generated from US Department of the Census data. Or for example italy
map which provides subregions, such as in a pair of lines of code is possible to plot it:
it <- ggplot2::map_data("italy")
library(ggplot2)
ggplot(it, aes(long, lat, group = group)) +
geom_polygon() +
coord_fixed()
I would like to obtain same maps for another countries but unfortunately I think that maps
package only provides this information for USA, Italy and France. Is there a package which provides such information?
Based on the @alistaire's comment:
library("rnaturalearth")
library("ggplot2")
spain <- ne_states(country = "spain", returnclass = "sf")
ggplot(data = spain) +
geom_sf()
Created on 2019-01-20 by the reprex package (v0.2.1)
As proposed here regions can be obtained just using group_by
and summarise
:
spain %>%
group_by(region) %>%
summarise() %>%
ggplot() +
geom_sf() +
theme(legend.position = 'none')
Created on 2019-02-12 by the reprex package (v0.2.1)
这篇关于如何获取包含区域和子区域的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!