地图可视化绘制 | R-cartography 艺术地图绘制

本期推文我们介绍一个可以绘制颇具“艺术”风格地图的可视化包-cartography,主要涉及的内容如下:

  • R-cartography 简介

  • R-cartography 实例应用

  • 所有完整代码都已整理之我们的线上课程,有需要的同学+v yidianshuyulove 咨询

R-cartography 简介

说到cartography包,用Python绘图的小伙伴可能会想到cartopy(Basemap的下一代地图可视化绘制包),下面就简单介绍下cartography。

  1. 官网介绍

cartography官网如下:http://riatelab.github.io/cartography/docs/articles/cartography.html (可点击 cartography官网)官方介绍如下:cartography包的目的是获得具有经典制图或GIS软件构建的主题图的视觉质量的主题图。用户可能属于以下两类之一:使用R的制图师或愿意创建地图的使用者。制图使用sf或sp对象生成基本图形。由于程序包的大多数内部结构都依赖于sf功能,因此空间对象的首选格式是sf。(官方直译的哈)

通过介绍我们可以知道,cartography主要基于sf对象进行绘图,所以我们在绘制之前需将数据(地图数据或者点数据)转换成sf对象。

  1. 可视化专题图介绍

cartography包官网提供了多种优秀的地图可视化绘制专题,这类可视化作品和一般的地图作品有些不一样,透露出一种“艺术 ”气息。 这里我们列举几个比较样例供大家参考,更多样例可参看官网哦!

  • 样例1

library(sf)
library(cartography)
# path to the geopackage file embedded in cartography
path_to_gpkg <- system.file("gpkg/mtq.gpkg", package="cartography")
# import to an sf object
mtq <- st_read(dsn = path_to_gpkg, quiet = TRUE)
# download osm tiles
mtq.osm <- getTiles(
  x = mtq,
  type = "OpenStreetMap",
  zoom = 11,
  crop = TRUE
)
# plot osm tiles
tilesLayer(x = mtq.osm)
# plot municipalities (only borders are plotted)
plot(st_geometry(mtq), col = NA, border = "grey", add=TRUE)
# plot population
propSymbolsLayer(
  x = mtq,
  var = "POP",
  inches = 0.25,
  col = "brown4",
  legend.pos = "topright",
  legend.title.txt = "Total population"
)
# layout
layoutLayer(title = "Population Distribution in Martinique",
            sources = "Sources: Insee and IGN, 2018\n© OpenStreetMap contributors.\nTiles style under CC BY-SA, www.openstreetmap.org/copyright.",
            author = paste0("cartography ", packageVersion("cartography")),
            frame = FALSE, north = FALSE, tabtitle = TRUE)
# north arrow
north(pos = "topleft")

可视化结果如下:

地图散点图

  • 样例2

library(sf)
library(cartography)
# path to the geopackage file embedded in cartography
path_to_gpkg <- system.file("gpkg/mtq.gpkg", package="cartography")
# import to an sf object
mtq <- st_read(dsn = path_to_gpkg, quiet = TRUE)
# transform municipality multipolygons to (multi)linestrings
mtq_pencil <- getPencilLayer(
  x = mtq,
  size = 400,
  lefthanded = F
)
# plot municipalities (only the backgroung color is plotted)
plot(st_geometry(mtq), col = "white", border = NA, bg = "lightblue1")
# plot administrative status
typoLayer(
  x = mtq_pencil,
  var="STATUS",
  col = c("aquamarine4", "yellow3","wheat"),
  lwd = .7,
  legend.values.order = c("Prefecture",
                          "Sub-prefecture",
                          "Simple municipality"),
  legend.pos = "topright",
  legend.title.txt = "",
  add = TRUE
)
#  plot municipalities
plot(st_geometry(mtq), lwd = 0.5, border = "grey20", add = TRUE, lty = 3)
# labels for a few  municipalities
labelLayer(x = mtq[mtq$STATUS != "Simple municipality",], txt = "LIBGEO",
           cex = 0.9, halo = TRUE, r = 0.15)
# title, source, author
layoutLayer(title = "Administrative Status",
            sources = "Sources: Insee and IGN, 2018",
            author = paste0("cartography ", packageVersion("cartography")),
            north = FALSE, tabtitle = TRUE, postitle = "right",
            col = "white", coltitle = "black")
# north arrow
north(pos = "topleft")

可视化结果如下:

铅笔风格主题地图

R-cartography 实例应用

我们使用之前空间插值系列的数据进行不同主题地图的绘制,首先 ,我们将所使用数据转换成sf对象,代码如下:

library(sf)
library(cartography)
library(openxlsx) # 读取Excel数据

jiangsu_shp <- "江苏省.json"
jiangsu <- sf::read_sf(jiangsu_shp)

file <- "pmdata.xlsx"
scatter_df <- read.xlsx(file)

scatter_sf <- st_as_sf(scatter_df,coords = c("lon", "lat"),crs = 4326)

接下来,我们进行部分样例的可视化绘制:

  • 演示-1

plot(sf::st_geometry(jiangsu),col="#f2efe9", border="#b38e43", bg = "#aad3df",lwd = 0.5)
# plot PM2.5
propSymbolsLayer(
  x = scatter_sf,
  var = "PM2.5",
  #inches = 0.18,
  col = "brown4",
  legend.pos = "topright",
  legend.title.txt = "PM2.5"
)
# layout
layoutLayer(title = "PM2.5 Values in NanJing",
            author = paste0("cartography ", packageVersion("cartography"),"\nVisualization by DataCharm"),
            frame = FALSE, north = FALSE, tabtitle = TRUE)
# north arrow
north(pos = "topleft")

可视化结果如下:

当然,我们还可以添加类别(label)属性进行绘制:

  • 演示-2

#par(mar = c(0.5,1,0.5,0.5))
# Plot the municipalities
pdf("G:\\DataCharm\\可视化包介绍(绘制)\\空间相关\\cartography_02.pdf")
plot(st_geometry(jiangsu), col="#f2efe9", border="#b38e43", bg = "#aad3df",
     lwd = 0.5)
# Plot symbols with choropleth coloration
propSymbolsTypoLayer(
  x = scatter_sf,
  var = "PM2.5",
  inches = 0.25,
  symbols = "square",
  border = "white",
  lwd = .5,
  legend.var.pos = "topright",
  legend.var.title.txt = "PM2.5",
  var2 = "label",
  legend.var2.values.order = c("1", "2","3","4"),
  col = carto.pal(pal1 = "multi.pal", n1 = 4),
  legend.var2.pos = c(117, 32.5),
  legend.var2.title.txt = "Scatter Class"
)
# layout
layoutLayer(title="PM2.5 Values in NanJing",
            author = paste0("cartography ", packageVersion("cartography"),"\nVisualization by DataCharm"),
            scale = 5, frame = FALSE, north = FALSE, tabtitle = TRUE)
# north arrow
north(pos = "topleft")
dev.off()

可视化结果如下:

优质学习资源推荐

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/421034.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

阿里云全面降价,释放了什么信号?

元宵节刚过&#xff0c;阿里云就放了一个大招—— 今天&#xff08;2月29日&#xff09;上午&#xff0c;阿里云发布通告&#xff0c;宣布全线下调云产品官网售价。这次降价涉及计算、存储、数据库等在内的100多款产品&#xff0c;平均降价幅度超过20%&#xff0c;最高降幅达55…

day07_分类管理EasyExcel品牌管理

文章目录 1 分类管理1.1 菜单添加1.2 表结构介绍1.3 页面制作1.4 列表查询1.4.1 需求分析1.4.2 后端接口CategoryCategoryControllerCategoryServiceCategoryMapperCategoryMapper.xml 1.4.3 前端对接category.jscategory.vue 2 EasyExcel2.1 数据导入导出意义2.2 EasyExcel简介…

1950-2022年各省逐年平均降水量数据

1950-2022年各省逐年平均降水量数据 1、时间&#xff1a;1950-2022年 2、指标&#xff1a;省逐年平均降水量 3、范围&#xff1a;33省&#xff08;不含澳门&#xff09; 4、指标解释&#xff1a;逐年平均降水数据是指当年的日降水量的年平均值&#xff0c;不是累计值&#…

【leetcode】环形链表✚环形链表II

大家好&#xff0c;我是苏貝&#xff0c;本篇博客带大家刷题&#xff0c;如果你觉得我写的还不错的话&#xff0c;可以给我一个赞&#x1f44d;吗&#xff0c;感谢❤️ 目录 1.环形链表解题拓展&#xff1a; 2.环形链表II 1.环形链表 点击查看题目 解题 思路: bool hasCycle…

【问题记录】pip install遇到“No space left on device“

一、pip安装包的过程中出现以下问题 二、问题溯源 【1】刚开始以为是空间不足&#xff0c;后来 df -h 看了一下&#xff0c;pip安装目录下空间绝对足够&#xff01;明显不是空间不足的问题。 【2】后来查了一下&#xff0c;发现是home目录下的空间满了&#xff0c;pip安装时&…

一台工控机的能量

使用Docker搭建EPICS的IOC记录 Zstack EPICS Archiver在小课题组的使用经验 以前电子枪调试&#xff0c;用一台工控机跑起束测后台&#xff0c;这次新光源用的电子枪加工回来又是测试&#xff0c;又是用一台工控机做起重复的事&#xff0c;不过生命在于折腾&#xff0c;重复的…

计算机网络-网络互连和互联网(五)

1.路由器技术NAT&#xff1a; 网络地址翻译&#xff0c;解决IP短缺&#xff0c;路由器内部和外部地址进行转换。静态地址转换&#xff1a;静态NAT&#xff08;一对一&#xff09; 静态NAT&#xff0c;内外一对一转换&#xff0c;用于web服务器&#xff0c;ftp服务器等固定IP的…

C++ 入门(七)— 基本数据类型

文章目录 Void整数有符号整数无符号整数固定宽度的整数和size_t 浮点数布尔值字符类型转换 Void Void 是最容易解释的数据类型。void 没有类型 不返回值的函数 最常见的是&#xff0c;void 用于指示函数不返回值&#xff1a; void writeValue(int x) {std::cout <<…

【MySQL】数据库中常用的函数

目录 聚合函数COUNT()函数的多种用法COUNT(*)COUNT(主键)COUNT(1)COUNT(常量)COUNT(非主键)COUNT(distinct(字段)) COUNT()函数小结 字符函数length(str)函数&#xff1a;获取参数值的字节个数concat(str1,str2,...)函数&#xff1a;字符串拼接upper(str)、lower(str)函数:大小…

部署Docker私有镜像仓库Harbor

Harbor介绍 Harbor 是为企业用户设计的开源镜像仓库项目&#xff0c;包括了权限管理(RBAC)、LDAP、审计、安全漏洞扫描、镜像验真、管理界面、自我注册、HA等企业必需的功能&#xff0c;同时针对中国用户的特点&#xff0c;设计镜像复制和中文支持等功能。 官网&#xff1a;h…

kotlin开发环境搭建,算法题+JVM+自定义View

什么是中年危机 根据权威数据显示&#xff0c;国内IT程序员鼎盛时期是在25-27岁左右&#xff0c;30岁对于程序员而言完全是一个38线&#xff0c;接着就是转业转岗的事情&#xff0c;这一点在业界也算是一个共识了。 大学毕业步入IT行业普遍年龄也是在22岁左右&#xff0c;然而…

线程安全的队列

学习一下别人写的&#xff0c;线程安全的队列代码。https://github.com/markparticle/WebServer/blob/master/code/log/blockqueue.hhttps://github.com/markparticle/WebServer/blob/master/code/log/blockqueue.h /** Author : mark* Date : 2020-06-16* copy…

20240301作业

1.使用fwrite、fread将一张随意的bmp图片&#xff0c;修改成德国的国旗 #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> int main(int argc, const char *argv[]) {FILE* fp fopen("./gaoda.bmp","…

Attention 中的 Q, K, V

Attention 中的 Q, K, V flyfish Attention Is All You Need. Q query 查询 K key 键 V value 值 简单理解 一篇文章&#xff0c;文章的标题就是key&#xff0c;文章的内容就是V 使用搜索引擎时&#xff0c;输入到 搜索栏中的文本 就是 query 输入内容 query 与 文章标…

你不可不知的数据安全词汇都在这!

关注公众号&#xff0c;回复关键词 “数据安全”&#xff0c;即可获取报告完整版 随着数字化时代的快速发展&#xff0c;数据安全已成为全球企业和组织面临的一项重大挑战。在这一背景下&#xff0c;我们深感需要有一个统一的、全面的数据安全术语基础&#xff0c;以便行业从业…

P2040 打开所有的灯

题目传送门&#xff1a;P2040 打开所有的灯 用深度优先搜索实现的一个填色题。 题目步骤&#xff1a; 1..dfs 首先dfs要判断是否符合题意&#xff0c;如果符合题意就更新最短路&#xff1b; 如果不符合题意就枚举 如果是关的就把周围四个包括 给标记上和原来相反的&#xf…

Redis--持久化机制详解

什么是redis持久化&#xff1f; Redis持久化是将内存的数据持久化到磁盘上&#xff0c;防止Redis宕机或者断点的时候内存中的数据丢失&#xff0c;把内存中的数据写入到磁盘的过程叫持久化。 Redis持久化的方式&#xff1f; RDB&#xff08;Redis DataBase&#xff09;&…

【YOLO v5 v7 v8 小目标改进】中心化特征金字塔(CFP) = 特征金字塔 + 显式视觉中心(EVC)+ 全局集中调节(GCR)

中心化特征金字塔&#xff08;CFP&#xff09; 特征金字塔 显式视觉中心&#xff08;EVC&#xff09; 全局集中调节&#xff08;GCR&#xff09; 提出背景中心化特征金字塔&#xff08;CFP&#xff09;CFP 架构图问题&#xff1a;不同尺度的对象检测问题&#xff1a;有限感受…

LeetCode //C - 118. Pascal‘s Triangle

118. Pascal’s Triangle Given an integer numRows, return the first numRows of Pascal’s triangle. In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown: Example 1: Input: numRows 5 Output: [[1],[1,1],[1,2,1],[1,…

Spring Cloud 构建面向企业的大型分布式微服务快速开发框架+技术栈介绍

分布式架构图 Cloud架构清单 Commonservice&#xff08;通用服务&#xff09; 1&#xff09;清单列表 2&#xff09;代码结构 Component&#xff08;通用组件&#xff09; 1&#xff09;清单列表 2&#xff09;代码结构 快速开发管理平台——云架构【系统管理平台】 一…