- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如下图所示,如何将图例放置到网格中的最后一个单元格?
我使用的代码是
psp1 <- tm_shape(province) +
tm_borders(col = 'black') +
tm_shape(county) +
tm_polygons(col = 'estimate', title = 'Changes in %', style = 'fixed', palette = brewer.pal(n = 6, name = 'Spectral'),
breaks = c(-15, -10, -5, 0, 5, 10, 15), legend.hist = F) +
tm_facets('warming', ncol = 2) +
tm_shape(province) +
tm_borders(col = 'black') +
tm_compass(north = 0, type = 'arrow', show.labels =0, position = c('right','top')) +
tm_layout(legend.format = list(fun = function(x) formatC(x, digits = 1, format = "f")),
fontface = 'bold',
legend.text.size = 1.3,
legend.width = 0.2,
legend.title.size = 1.5,
panel.label.size = 1.5,
panel.label.fontface = 'bold')
数据可以从here中找到.谢谢。
最佳答案
我的回答可能有点晚了......(在你提出请求后将近一年!)无论如何,你的问题很有趣,我希望这个答案对你有用,无论是现在还是 future 的项目或其他 SO 用户(顺便说一下,感谢您让您的输入数据可访问一年 ;-))。
据我所知,使用tmap
库的tm_facets()
函数无法解决您的问题。因此,我建议使用一种略有不同的“策略”(仍然使用 tmap
库)来获取您要查找的内容。
它分为两个步骤:
手动构建 map 和图例...幸运的是,不是完全手动,因为我建议的解决方案使用一个通过 运行的自定义函数(即
函数。make_graph()
) >Map()
使用 R base
grid
库编辑带有图例的 map 镶嵌。同样,通过使用通过 Map()
函数运行的一个自定义函数(即 Maps_setup()
),实现变得更加容易。
因此,请在下面找到详细说明该方法的代表。
library(sf)
library(tmap)
library(RColorBrewer)
# Import data
province <- st_read("province.shp")
county <- st_read("county.shp")
# Split the 'sf' object 'county' into a list of five 'sf' objects corresponding
# to the five warming scenarios (i.e. the first five facets of the final figure)
county_warm_list <- split(county , f = county$warming)
# Build the function 'make_graph' to generate the maps
make_graph <- function(x,y){
results <- tm_shape(x,
is.master = TRUE) +
tm_polygons(col = 'estimate',
title = 'Changes in %',
style = 'fixed',
palette = brewer.pal(n = 6, name = 'Spectral'),
breaks = c(-15, -10, -5, 0, 5, 10, 15),
legend.hist = FALSE,
midpoint = 0) +
tm_shape(province) +
tm_borders(col = 'black') +
tm_compass(north = 0,
type = 'arrow',
show.labels = 0,
position = c(0.93, 0.87),
size = 1.2) +
tm_layout(legend.show = FALSE,
# NB: the use of the 'get_asp_ratio()' function enables
# to optimize the size of each map inside its own facet:
asp = tmaptools::get_asp_ratio(x),
panel.labels = y,
panel.label.size = 0.8,
panel.label.fontface = 'bold',
inner.margins = c(0.02, 0.02, 0.02, 0.02))
return(results)
}
# Run the 'make_graph()' function through the list of the five 'sf' objects (i.e.
# 'county_warm_list') to generate the maps with their respective title using
# the 'Map()' function
map_titles <- names(county_warm_list)
Maps_list <- Map(make_graph, county_warm_list, map_titles)
# Build the legend using only the object "county"
Maps_legend <- tm_shape(county) +
tm_polygons(col = 'estimate',
title = 'Changes in %',
style = 'fixed',
palette = brewer.pal(n = 6, name = 'Spectral'),
breaks = c(-15, -10, -5, 0, 5, 10, 15),
legend.hist = FALSE,
midpoint = 0) +
tm_layout(legend.only = TRUE,
legend.position = c("center", "center"),
legend.format = list(fun = function(x) formatC(x, digits = 1, format = "f")),
fontface = 'bold',
legend.text.size = 1.3,
legend.width = 0.2,
legend.title.size = 1.5)
# Add the legend to 'Maps_list'
Maps_list$Legend <- Maps_legend
第一步结束时,您会得到一个包含 6 个元素(即五张 map 和一个图例)的列表(即 Maps_list
)。
library(grid)
grid.newpage()
# Build the function 'Maps_setup' to set up the layout
Maps_setup <- function(x,y,z){
pushViewport(viewport(layout = grid.layout(nrow = 3, ncol = 2,
widths = unit(7.32, "cm"),
heights = unit(5, "cm"))))
setup <- print(x, vp = viewport(layout.pos.row = y, layout.pos.col = z))
return(setup)
}
# Run the 'Maps_setup()' function through the six objects of 'Maps_list' (i.e.
# 5 maps + 1 legend) to place the maps and the legend on the page using
# the 'Map()' function
# The 'pos_row' and 'pos_col' vectors are used to indicate where to place the
# maps as the 'Maps_setup()' function works through the list
pos_row <- rep(1:3, each = 2)
pos_col <- rep(1:2, times = 3)
Final_Results <- Map(Maps_setup, Maps_list, pos_row, pos_col)
由 reprex package 创建于 2022-01-25 (v2.0.1)
关于r - 这个图例的位置怎么安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65964613/
我们有一个接口服务为下游的系统提供数据服务,本来好好的大家都愉快地传递JSON,非常和谐。可最近有个新需求去对接一个很老的系统,这倒是不算啥,可这个老系统数据不是以JSON传递的而是以XML传递
我想完成这样的事情: results = [] for i in range(N): data = generate_data_slowly() res = tasks.process
如何安排 SSIS 每天在给定时间从文件中自动执行包? 最佳答案 你有几个选择,但我会给你一些让你快速启动和运行的东西...... 打开 SQL Server Management Studio 并连
我们有两个服务器 Azure 配置,运行由 Umbraco 提供支持的网站。当我们需要向Azure服务器添加新域时,我们修改配置文件,然后依次重新启动每台服务器。 理论上,因为我们永远不会同时重新启动
我给出了一个创建电子邮件 C# 控制台应用程序的任务,该应用程序的目标是批量运行。我对 C# 领域非常陌生,因此我不知道我的方向。此 C# 控制台应用程序将部署在服务器上,并期望根据服务器时间在特定时
我有一个控制台应用程序,运行时会执行一些操作,并使用docker生成它的镜像。现在,我想将其部署到Kubernetes并每小时运行一次,是否有可能在K8中完成? 我已经阅读了有关Cron作业的信息,但
这是我的 CronJob 规范的一部分: kind: CronJob spec: schedule: #{service.schedule} 对于特定环境,设置了 cron 作业,但我从不希望
我的任务是创建一个应用程序,该应用程序将每 (n) 分钟向选定的收件人发送一封电子邮件。它所在的应用程序的结构方式是通过回调 .main(args) 来重置自身。每当需要的时候。我的问题是,当我调用.
安排 Airflow Dag 使其仅在工作日运行的正确方法是什么?我已经尝试在 start_date 和 schedule_interval 表达式中都包含小时偏移量,但它仍然没有在所需的时间开始。
我有许多测试都安排了一些 TestFixtures,我发现我正在复制该安排代码很多。每个测试的前几行几乎相同。 有没有一种方法可以在所有测试中声明一个共享的 TestFixture,同时仍然在每个测试
我有一个问题,我正在创建一个应用程序,我想在系统与 azan 时间匹配时在后台播放 azan 文件,无论用户正在使用应用程序的任何屏幕,azan 都应该开始播放。 我在 Azan.java 中创建了一
在我没有重启我的手机之前一直在 toast ,但是在重启之后 broadcastreceiver2 没有收到并且没有任何反应。 我关注了http://stacktips.com/tutorials/a
自动将一个数据库表的表数据复制到另一个数据库表;当表格更新或按某个特定时间间隔更新时,安排 数据库MySQL;语言 PHP 我有两个数据库; A和B 数据库 A 包含一个表 USERS 我想将USER
我的 Android 应用程序将定期轮询服务器以检查数据。我希望无论用户与应用程序交互如何进行此轮询,类似于(在概念上)Gmail 和 Google Reader 应用程序如何在后台同步数据。安装应用
我可以将android中的警报管理器(.set()方法)安排到当前时间一个月后的时间吗它会活那么久吗?操作系统对此 alarmManager 有何影响? 最佳答案 用户重启手机时的提示。您可以使用以下
安排 AsyncTask 每分钟运行一次的最佳做法是什么(请注意,在 AsyncTask 完成后我应该能够更新 UI)。 我不打算使用服务,因为这些任务应该只在应用处于 Activity 状态时运行。
我在排列从 php 中的 while 循环返回的数据时遇到问题。 基本上,我正在尝试从数据库返回工作的时间段计划,问题是我似乎在所有时间段中得到相同的结果,或者在一个时间段中的所有客户端得到相同的结果
我想创建一个仅在周六和周四运行的 mysql 事件。 是否可以定义事件本身的日期? 我有一个想法,每天运行调度程序,如果是星期四或星期六,则该过程将继续,否则它将退出调度程序而不执行任何操作。 最佳答
如何使用 MySQL 调度程序安排查询运行(如果这是最好的方法)?我按照 link here 中的说明进行操作但我有点迷路了。 我想在我们拥有的特定数据库上每 30 分钟运行一次以下查询。 u
我想在使用事件轮换我的日志后读取我的表日志,我希望我的事件在我选择的一周中的任何一天运行。 经过一番研究,我想到了这个 CREATE EVENT read_rotated_logs ON SCHEDU
我是一名优秀的程序员,十分优秀!