R包:ggspatial空间画图

devtools/2024/9/29 21:42:09/

在这里插入图片描述

ggplot2语法的空间图形画图

Spatial data plus the power of the ggplot2 framework means easier mapping.

加载R包

# install.packages("ggspatial")library(ggplot2)
library(ggspatial)
load_longlake_data()

Using layer_spatial() and annotation_spatial()

ggplot() +annotation_spatial(longlake_waterdf) +layer_spatial(longlake_depthdf, aes(col = DEPTH_M))

在这里插入图片描述

With raster layers, you can also use layer_spatial()

ggplot() + layer_spatial(longlake_depth_raster, aes(fill = after_stat(band1))) +scale_fill_viridis_c(na.value = NA)

在这里插入图片描述

Using north arrow and scalebar

ggplot() +annotation_spatial(longlake_waterdf) +layer_spatial(longlake_depthdf, aes(col = DEPTH_M)) +annotation_scale(location = "tl") +annotation_north_arrow(location = "br", which_north = "true")

在这里插入图片描述

Tile map layers

ggplot() +annotation_map_tile(type = "osm") +layer_spatial(longlake_depthdf, aes(col = DEPTH_M))

在这里插入图片描述

Data frames with coordinates

cities <- data.frame(x = c(-63.58595, 116.41214), y = c(44.64862, 40.19063), city = c("Halifax", "Beijing")
)ggplot(cities, aes(x, y)) +annotation_map_tile(type = "stamenwatercolor") +geom_spatial_point() +geom_spatial_label_repel(aes(label = city), box.padding = 1) +coord_sf(crs = 3995)

在这里插入图片描述

案例

library(ggplot2)
library(ggspatial)
load_longlake_data()ggplot() +# loads background map tiles from a tile sourceannotation_map_tile(zoomin = -1) +# annotation_spatial() layers don't train the scales, so data stays centralannotation_spatial(longlake_roadsdf, size = 2, col = "black") +annotation_spatial(longlake_roadsdf, size = 1.6, col = "white") +# raster layers train scales and get projected automaticallylayer_spatial(longlake_depth_raster, aes(colour = after_stat(band1))) +# make no data values transparentscale_fill_viridis_c(na.value = NA) +# layer_spatial trains the scaleslayer_spatial(longlake_depthdf, aes(fill = DEPTH_M)) +# spatial-aware automagic scale barannotation_scale(location = "tl") +# spatial-aware automagic north arrowannotation_north_arrow(location = "br", which_north = "true")

在这里插入图片描述

参考

  • https://paleolimbot.github.io/ggspatial/articles/ggspatial.html

http://www.ppmy.cn/devtools/118901.html

相关文章

C语言 | Leetcode C语言题解之第437题路径总和III

题目&#xff1a; 题解&#xff1a; /*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/ //递归遍历树节点&#xff0c;判断是否为有效路径 int dfs(struct TreeNode * root, int ta…

深入剖析 Android Lifecycle:构建高效稳定的应用

在 Android 开发中&#xff0c;管理应用组件的生命周期是至关重要的。正确处理生命周期事件可以确保应用的性能、稳定性和用户体验。Android Framework 提供了一系列的机制来管理应用组件的生命周期&#xff0c;而android.arch.lifecycle库则为我们提供了更简洁、更灵活的方式来…

【Linux】初识进程

目录 基本概念 PCB task_struct task_struct内容分类 组织进程 查看进程 查看正在运行的进程信息 获取pid和ppid 创建子进程 基本概念 一个已经加载到内存中的程序&#xff0c;叫做进程&#xff0c;正在运行的程序&#xff0c;叫做进程&#xff0c;进程是担当分配系统…

Unity3D 中构建行为树插件详解

前言 在Unity3D中&#xff0c;行为树&#xff08;Behavior Tree&#xff09;是一种用于游戏AI设计和实现的高级工具&#xff0c;它提供了一种结构化和模块化的方式来管理游戏实体的行为。行为树通过树状结构组织了一系列节点&#xff0c;每个节点代表了一个决策或动作。这种结…

学Python再学C++是走弯路?

随着编程教育的普及&#xff0c;越来越多的家长和学生开始选择学习编程语言。Python作为一种简洁易学、应用广泛的编程语言&#xff0c;成为许多编程初学者的首选。然而&#xff0c;随着学习的深入&#xff0c;很多人会考虑转向更复杂、更底层的语言&#xff0c;如C。这就引发了…

二十、微服务(基本概念与SOA的区别)

微服务架构(Microservices Architecture)是近年来在软件开发中广受欢迎的架构风格,尤其在构建大型、复杂系统时展现出巨大优势。它与SOA(面向服务架构)在理念上有相似之处,但在实现方式、设计原则以及应用场景上存在显著区别。 微服务架构的基本概念 微服务架构是一种将…

自然语言处理实战项目:从理论到实现

一、引言 自然语言处理&#xff08;NLP&#xff09;是计算机科学、人工智能和语言学交叉的领域&#xff0c;旨在让计算机能够理解、处理和生成人类语言。随着互联网的飞速发展&#xff0c;大量的文本数据被产生&#xff0c;这为自然语言处理技术的发展提供了丰富的素材&#xf…

23个Python在自然语言处理中的应用实例

在自然语言处理&#xff08;NLP&#xff09;领域&#xff0c;Python作为一门功能强大的编程语言&#xff0c;凭借其丰富的库和工具集&#xff0c;成为了实现各种NLP任务的首选。以下是一个关于Python在NLP中应用的广泛实例的前言&#xff0c;旨在概述Python在NLP领域的多样性和…