measles <- read.csv("~/Downloads/measles.csv")
# reorder the data in chronological order
measles <- measles[order(measles$year, decreasing = FALSE),]
Measles is a highly contagious viral illness affecting the respiratory system. It spreads through the air when infected persons cough, sneeze, and breathe. According to the Centers for Disease Control and Prevention, a pronounced rash will appear on the face and neck 3-5 days after exposure. The rash will then spread downwards to the rest of the body. Complications from the disease include blindness, diarrhea, severe breathing problems, and encephalitis which can lead to brain damage. Most deaths related to measles are a result of these complications. The following graph explores measles cases per year between 1980 and 2017, to see how the number of cases has changed over time.
par(mar=c(5.1, 5, 4.1, 2.1))
barplot(height = measles$measles.cases / 1000000, names.arg = measles$year, las=2,
cex.names = 0.8, space = 1, col="lightblue",
main="Annual Measles Cases", xlab = "Year", ylab = "Number of Cases (Millions)")
This graph demonstrates the number of measles cases that occurred each
year from 1980 to 2017. The graph illustrates there has been a steady
decline in cases over the years. Although the decline in cases has been
consistent, the graph also shows that there have been spikes in cases.
According to the World Health Organization, prior to the availability of
a vaccine in 1963, there were major measles epidemics every 2-3 years.
The spikes in the above graph shows a similar trend even as overall
cases decline.
From the graph above, it can be observed that measles cases declined over the time interval 1980-2017. However, the previous graph does not explain why cases have declined - only that cases have declined over time. To understand why cases have delcined, we introduce a new variable, vaccination coverage. The graph below explores the relationship between the vaccination coverage rates and the number of measles cases between the years of 1985 and 2005. Prior to plotting this graph, it is reasonable to predict that as vaccination coverage increases, measles cases will decrease as a result.
library(plotly)
# Subset the data to only include years 1985-2005
measles_subset <- measles[measles$year %in% 1985:2005,]
p <- plot_ly(data = measles_subset, type = "scatter", mode = "markers",
x= ~vaccination.coverage, y = ~measles.cases, color = ~year,
text = ~paste("Year:", year,
"\nVaccination Coverage (%):", vaccination.coverage,
"\nMeasles Cases:", measles.cases)) %>%
layout(title = "Vaccination Coverage Compared to Measles Cases (1985-2005)",
xaxis = list(title = "Vaccination Coverage (%)"),
yaxis = list(title = "Measles Cases"))
p
As mentioned, this graph demonstrates the relationship between vaccination coverage and the number of total measles cases per year. Hovering over the points reveals information about the year, number of cases, and vaccination coverage. It can be observed that as vaccination coverage increases, the number of measles cases decreases. The graph also shows that vaccination coverage increased with time as demonstrated by the color gradient. Furthermore, according to the CDC, there was an measles outbreak among vaccinated school-aged children in 1989. This outbreak, which can be seen in the graph as a jump between the points for 1988 and 1989, resulted in a recommendation for a second measles vaccine dose which can also be seen to have lowered cases for the following years.
########################################################################################
## Note:
##
## Two-Axis plotting code adapted from StackOverflow post by user Daniel Rajdl.
## https://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes
##
## Legend code adapted from StackOverFlow post by user Roman Luštrik.
## https://stackoverflow.com/questions/15997121/add-pch-symbol-in-r-plot-legend
##
########################################################################################
par(mar = c(5, 4, 4, 4) + 0.3)
barplot(height = measles$measles.cases / 1000000, names.arg = measles$year, las=2,
cex.names = 0.8, space = 1, col="lightblue",
main="Annual Measles Cases Compared to Vaccination Coverage",
xlab = "Year", ylab = "Number of Cases (Millions)")
legend ("right", legend = c("Measles Cases", "Vaccination Coverage"),
col = c("lightblue","red"), lty = c(NA, 1), pch = c(15, NA), cex = 0.8, title = "Legend",
text.font = 2)
par(new = TRUE)
plot(measles$year, measles$vaccination.coverage, type = "l", axes = FALSE,
bty = "n", xlab = "", ylab = "", col="red", lwd = 2)
axis(side=4, at = pretty(range(measles$vaccination.coverage)), col = "red")
mtext("Vaccination Coverage (%)", side=4, line=3)