modify this code to remove the last error Load required libraries library(dplyr)…
- User
modify this code to remove the last error
Load required libraries
library(dplyr) library(lubridate) library(tidyr) library(ggplot2) library(sf) library(leaflet) library(htmlwidgets) library(prophet) library(RColorBrewer) library(rworldmap)
Assume that ‘data’ is pre-loaded dataframe containing the COVID-19 data
Clean data
data <- data %>%
-
mutate( -
state = replace_na(state, "Unknown"), -
date = as.Date(date), -
lat = as.numeric(lat), -
lon = as.numeric(lon) -
) %>% -
filter( -
lat >= -90 & lat <= 90 & -
lon >= -180 & lon <= 180 & -
!(confirmed == 0 & recovered == 0 & death == 0) -
)
Aggregate data by state
agg_data <- data %>%
-
group_by(state) %>% -
summarise( -
total_confirmed = sum(confirmed), -
total_recovered = sum(recovered), -
total_deaths = sum(death) -
) %>% -
ungroup()
Visualizations
Top states by confirmed cases
top_states_confirmed <- agg_data %>%
-
arrange(desc(total_confirmed)) %>% -
head(10)
ggplot(top_states_confirmed, aes(x=reorder(state, total_confirmed), y=total_confirmed)) +
-
geom_bar(stat="identity", fill="steelblue") + -
coord_flip() + -
labs(title="Top 10 States by Confirmed Cases", x="State", y="Total Confirmed Cases")
-
- Assistant