# Load libraries
library(tidyverse)
library("dslabs")
library(highcharter)
library(RColorBrewer)
# data(package="dslabs")
# Load data
data("us_contagious_diseases")Data110 Assignment W8
Introduction:
In this Assignment, I use the dataset “us_contagious_diseases” from the “dslabs” package. It contains Yearly counts for Hepatitis A, Measles, Mumps, Pertussis, Polio, Rubella, and Smallpox for US states. Original data courtesy of Tycho Project (http://www.tycho.pitt.edu/).
Load libraries and data
Filter, clean and arrange data
years <- c(1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004)
diseases <- c("Hepatitis A", "Measles", "Mumps", "Pertussis", "Rubella")
# Filter data for the state of Maryland for years from 1990 to 2004 for Hepatitis A, Measles, Mumps, Pertussis, and Rubella
my_data <- us_contagious_diseases |>
filter(state == "Maryland" & year %in% years & disease %in% diseases & !is.na(count))|>
arrange(year) # Arrange data by yearVisualization of Contagious Disease Trends in Maryland (1990-2004)
# Chart of temporal trends of reported contagious disease cases
colors <- brewer.pal(5, "Set1")
my_chart <- highchart(theme = hc_theme_economist()) |>
hc_title(text = "Contagious Diseases Trends in Maryland from 1990 to 2004") |>
hc_add_series(data = my_data,
type = "line",
hcaes(x = year,
y = count,
group = disease)) |>
hc_colors(colors) |>
hc_xAxis(title = list(text="Year")) |>
hc_yAxis(title = list(text="Number of reported cases")) |>
hc_plotOptions(series = list(marker = list(symbol = "square"))) |>
hc_legend(align = "right",
verticalAlign = "bottom") |>
hc_tooltip(shared = TRUE,
borderColor = "brown",
pointFormat = "{point.disease}: {point.count}<br>") |>
hc_caption(text = "Source: http://www.tycho.pitt.edu/")
my_chartWe can observe that the number of cases for each disease decreased overall over the years, and mumps and rubella even disappeared after the year 2002.