ZL1023

V1

2023/01/18阅读:81主题:全栈蓝

R语言:不同级别的地图

一、前言

学术论文中的数据不仅具有时间属性,也具有空间属性。

地图是展示数据空间属性的重要工具。

根据研究区域的空间尺度,可以将地图简单划分为:

  • 世界地图;
  • 国家地图;
  • 局部地图。

1.1 世界地图-示例

文献来源
文献来源
原始图片
原始图片

1.2 中国地图-示例

文献来源
文献来源
原始图片
原始图片

二、R包

本期使用的R包主要有4个:

  • maps包:提供世界地图;
  • sf包:用于读取阿里云数据可视化平台的在线地图;
  • ggspatial包:用于绘制地图指北针等;
  • tidyverse包:用于绘制地图。

tidyverse包是一个集成包,包括

  1. ggplot2包:用于数据可视化;
  2. dplyr包:用于数据操作;
  3. tidyr包:用于数据整理;
  4. readr包:用于数据导入;
  5. purrr包:用于函数式编程;
  6. tibble:用于一种新型数据框;
  7. stringr包:用于字符串;
  8. forcats包:用于因子。
# load "maps" package
library(maps)
# load "sf" package
library(sf)
# load "ggspatial" package
library(ggspatial)
# load "tidyverse" package
library(tidyverse)

三、演示数据

3.1 世界地图

演示数据集简介:maps包提供了一张世界地图(分辨率为1:50 m),这张世界地图是自然地球项目于2013年发布的。自然地球项目的网址如下。

# web site
# https://www.naturalearthdata.com/
# get map data
world_map <- st_as_sf(maps::map("world",plot=FALSE,fill=TRUE))

3.2 中国地图

演示数据集简介:中国地图来源于阿里云数据可视化平台,阿里云数据可视化平台的底层数据源是高德地图,可放心食用。阿里云数据可视化平台的网址如下。

# web site
# http://datav.aliyun.com/portal/school/atlas/area_selector
# get map data
china_map = st_read("https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json")[c("adcode","name","geometry")]

3.3 局部地图

演示数据集简介:本期所选的局部地图为天津,天津地图来源于阿里云数据可视化平台。

# web site
# http://datav.aliyun.com/portal/school/atlas/area_selector
# get map data
tianjin_map = st_read("https://geo.datav.aliyun.com/areas_v3/bound/120000_full.json")[c("adcode","name","geometry")]

四、R语言实现

4.1 世界地图

# draw plot
ggplot()+
  # geometric layer
  geom_sf(data=world_map,fill=NA,color="black")+
  # visual mapping
  annotation_north_arrow(location="tr",style=north_arrow_fancy_orienteering())+
  annotation_scale(location="bl")+
  # coordinate adjustment
  coord_sf(crs=4326)+
  # theme adjustment
  theme_light()+
  theme(axis.text=element_text(color="black"))

4.2 中国地图

# draw plot
ggplot()+
  # geometric layer
  geom_sf(data=china_map,fill=NA,color="black")+
  # visual mapping
  annotation_north_arrow(location="tr",style=north_arrow_fancy_orienteering())+
  annotation_scale(location="bl")+
  # coordinate adjustment
  coord_sf(crs=21479)+
  # theme adjustment
  theme_light()+
  theme(axis.text=element_text(color="black"))

4.3 局部地图

# draw plot
ggplot()+
  # geometric layer
  geom_sf(data=tianjin_map,fill=NA,color="black")+
  # visual mapping
  annotation_north_arrow(location="tr",style=north_arrow_fancy_orienteering())+
  annotation_scale(location="bl")+
  # coordinate adjustment
  coord_sf(crs=4326)+
  # theme adjustment
  theme_light()+
  theme(axis.text=element_text(color="black"))

分类:

其他

标签:

教育

作者介绍

ZL1023
V1