I am trying to color a set of geographical points by a time variable using the tmap
function tm_dots
, but it keeps treating the time variable as a categorical variable. Is there a way to use a POSIXct
column as a continuous variable? Some example code demonstrating the problem is:
library(sf)
library(tmap)
df = data.frame(lon=1:20,lat=1:20,ts=as.POSIXct(paste0('2020-01-',1:20)))
df = st_as_sf(df,coords=c("lon","lat"),crs=4326)
tm_shape(df) + tm_dots(col="ts")
One "solution" would be to convert the dates into a number (e.g., number of days since the earliest date), and then use this numeric variable to color the points, perhaps using different labels in the legend to replace the numbers with the original dates, but this seems like a lot of work and is unlikely to produce satisfactory results without a lot of fiddling.