During this time of COVID, I have seen many interactive dashboards tracking the number of confirmed cases in different countries. I have wondered how do I create one.
When i started this course, I was very happy when i understood the concepts of R shiny and realized I could create interactive graphs and dashboard.
So for this weeks assignment, I have used the COVID deaths data in US till 12th May 2020 to create my first very simple interactive map showing the hotspots in US.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(leaflet)
data = read.csv("US_states.csv", header = TRUE, sep = ",")
agg = data %>%
group_by(Province_State, Latitude, Longitude) %>%
summarize(total_deaths = sum(Deaths))
agg = as.data.frame(agg)
agg$color = with(agg, ifelse(total_deaths > 1000, "red",
ifelse(total_deaths >=500 & total_deaths <1000, "blue", "green")))
col_palette = colorFactor(c("red", "blue", "green"), agg$zones)
agg %>%
leaflet() %>%
# setView(zoom = 12) %>%
addTiles() %>%
addCircleMarkers(lat = ~Latitude, lng = ~Longitude,
radius = ~sqrt(total_deaths),
weight = 1,
color = ~color,
popup = ~paste0("<b>", Province_State, "<b><br>",
"Total_deaths:", total_deaths)) %>%
addLegend("topleft",
labels = c(">1000",
">500 and <1000",
"<500"),
colors = c("red", "blue", "green"),
title = "Total Deaths till May 12 2020")
Zoom in and check the total number of deaths in each state till 12th May 2020.