r - tmap - 改变 tm_markers 的行为
问题描述
这是一个可重现的示例
#load the packages
library(easypackages)
packages("tidyverse","readxl","sf","tmaptools","tmap","lubridate",
"lwgeom","Cairo","nngeo","purrr","scales", "ggthemes","janitor")
polls<-st_as_sf(read.csv(url("https://www.caerphilly.gov.uk/CaerphillyDocs/FOI/Datasets_polling_stations_csv.aspx")),
coords = c("Easting","Northing"),crs = 27700)%>%
mutate(date = sample(seq(as.Date('2020/01/01'), as.Date('2020/05/31'), by="day"), 147))
test_stack<-polls%>%st_join(polls%>%st_buffer(dist=1000),join=st_within)%>%
filter(Ballot.Box.Polling.Station.x!=Ballot.Box.Polling.Station.y)%>%
add_count(Ballot.Box.Polling.Station.x)%>%
rename(number_of_neighbours = n)%>%
mutate(interval_date = date.x-date.y)%>%
subset(select = -c(6:8,10,11,13:18))## removing this comment will summarise the data so that only number of neighbours is returned %>%
distinct(Ballot.Box.Polling.Station.x,number_of_neighbours,date.x)%>%
filter(number_of_neighbours >=2)
polls%>%mutate(id = as.numeric(row_number()))%>% mutate(thing = case_when(id %% 2 == 0 ~ "stuff",
id %% 2 !=0 ~ "type"))->polls
qtm(polls)
tmap_mode("view")
tm_shape(polls) + tm_markers(col = "thing")
tm_shape(polls) + tm_dots(col ="thing", size = 0.75)
我想做的是改变 tm_markers 的颜色和大小,因为在我想要使用它的东西中,很容易使用不同的颜色标记。
与此相关的是,了解当地图模式为“视图”并生成 html 时标记的聚类是如何工作的。
对 tm_marker 行为和 tm_marker 聚类的任何帮助都会很棒。谢谢==“很多!”
解决方案
最后证明它比使用标记要简单得多。从美学上讲,我不喜欢“标记”,但我喜欢“点”,并且 tm_dots 可以让您更轻松地分类颜色(或者在我的脑海中更容易......)。事情是这样的。出色地。聚类可以应用于点、气泡和 tm_symbols。都在这里: https : //cran.r-project.org/web/packages/tmap/tmap.pdf(第 89/90 页)
反正
tm_shape(polls) + tm_dots(col ="thing", size = 0.75,clustering = T
)
这就是答案(对我来说)。我可以聚类然后按字段着色。
推荐阅读
- mysql - 也许如何从选择中选择
- c# - C#串行数据被分成随机数量,试图找到回车没有运气
- docker - 无法通过覆盖网络跨 2 个节点正确通信
- mysql - 如何在 MySQL 中查询此 JSON 有效负载?
- homebrew - 将 OpenCV 与 DarkNet 一起使用时出错 - 为自己的数据集生成锚点
- omnet++ - OMNET++:如何创建每秒触发的计时器事件?
- sql-server - SQL Server 时态表不保留删除历史记录以在事务中进行更新和删除
- excel - Excel-vba将不同的工作表保存到不同文件夹中的PDF
- clang - 在 Travis CI 上为 C++17 设置 Clang
- python - Keras 模型 (RNN) 预测 Floydhub 上的奇怪输出