I have a data frame called AQ_df that I am able to create a map with using leaflet however, I am only able to create the map for one specific time however, as you can see the "date" column changes over time (obviously). I want the colours on the map to change depending on the severity column and how it changes over time. Currently it automatically displays the data for latest timestamps of each location
An example of the data is as follows:
In order to create the map using leaflet I use the below code. this works fine however it only creates the map for the most recent timestamp in the dataframe. But I want the map to animate over the time window of the data i.e., start at 2021-08-12 00:30:00 and then finish at the last timestamp. How do I go about doing this? The map currently looks like image below.
AQ_df$severity = cut(AQ_df$PM_RAMP,
breaks=c(0,5,10,25,100,1000), right=FALSE,
labels=c("<5","5-10","10-25","25-100","100+"))
palette_rev <- rev(brewer.pal(5, "RdYlGn"))
pal <- colorFactor(
palette = palette_rev,
domain = AQ_df$severity
)
test_map <- leaflet(width="100%") %>%
setView(lng=-123.2504, lat= 49.2652, zoom=15) %>%
addProviderTiles("Esri.WorldStreetMap")
test_map %>%
addCircles(
data=AQ_df,
lng = ~Longitude,
lat = ~Latitude,
radius = 30,
color = 'black',
fillColor = ~pal(severity),
fillOpacity = 1,
weight=1,
popup = paste0("<strong>ID: </strong>", AQ_df$RAMP_label, "</br>",
"<strong>Location: </strong>", AQ_df$RAMP_desc, "</br>",
"<strong>PM2.5 (ug/m3): </strong>", AQ_df$PM_RAMP, "</br>",
"<strong>CO (ppb): </strong>", AQ_df$CO_RAMP, "</br>",
"<strong>NO (ppb): </strong>", AQ_df$NO_RAMP, "</br>",
"<strong>NO2 (ppb): </strong>", AQ_df$NO2_RAMP, "</br>",
"<strong>O3 (ppb): </strong>", AQ_df$O3_RAMP, "</br>",
"<strong>CO2 (ppm): </strong>", AQ_df$CO2_RAMP, "</br>",
#"<strong>Temperature (C): </strong>", AQ_df$T_RAMP, "</br>",
#"<strong>Relative Humidity (%): </strong>", AQ_df$RH_RAMP, "</br>",
"<strong>Date: </strong>", AQ_df$date)
) %>%
addLegend(
position = c("topright"),
pal=pal,
values=AQ_df$severity,
title="<strong>PM2.5 (ug/m3)</strong>")