Chapter 8 Visualizations with Leaflet II
8.1 Plot frequency of speed limit excesses
Now let’s procees the same way to visualize the frequency of speed exceses :
data.to.plot <-
OSM_sf.with.Uber %>% filter(hour == 2 & total_rows>50 &
fclass != 'motorway' & tunnel == 'F')
colorPalette <-
colorNumeric("Reds",
data.to.plot$ratio.over,
reverse = F)
leaflet(data.to.plot) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>% addPolylines(
color = ~colorPalette(data.to.plot$ratio.over),
weight = ~log(1+speed_minus_max),
label=~paste0(name,':',round(ratio.over,0),'% / ',round(speed_minus_max,0),' kph over in average'),
layerId = OSM_sf.with.Uber$osm_id)%>% addLegend("bottomright", pal = colorPalette, values = ~ratio.over,
title = "Speed excess frequency % ",
labFormat = labelFormat(suffix = " %"),
opacity = 1
)
## Warning in log(1 + speed_minus_max): NaNs produced