1

Here is a reproducible example

#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)

what I'd like to do is change the colour and size of tm_markers, because in the thing I want to use it in it would be nice to make use of different colour markers easily.

Linked to this, is understanding how the clustering of markers works when the map mode is "view" and an html is generated.

Any help on tm_marker behaviour and tm_marker clustering would be brilliant. thanks == "MANY!"

damo
  • 463
  • 4
  • 14

1 Answers1

0

In the end it turns out to be much simpler than using markers. I don't like "markers", aesthetically, but I do like "dots" and tm_dots lets you sort out the colours more easily (or in my head it's easier..) . And the thing is. Well. Clustering can be applied to dots, bubbles, and tm_symbols. It's all in here: https://cran.r-project.org/web/packages/tmap/tmap.pdf (p 89/90)

ANYWAY

tm_shape(polls) + tm_dots(col ="thing", size = 0.75,clustering = T)

that's the answer (for me). I can cluster and then colour by a field.

damo
  • 463
  • 4
  • 14