问题描述
这是一个可重复的例子
#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_symbol。 全部都在这里: https://cran.r-project.org/web/packages/tmap/tmap.pdf (p 89/90)
随便
tm_shape(polls) + tm_dots(col ="thing",size = 0.75,clustering = T
)
这就是答案(对我来说)。我可以聚类,然后按字段着色。