Assignment 1

Question 1

Measles is an extremely contagious disease that has historically affected millions of people worldwide every year. Groups 
that are most susceptible to measles complications include young children under 5 years old, pregnant women, adults over 20 years old, and people with compromised immune systems. Out of all infectious diseases, measles is the most infectious, where 90% of susceptible people who come in contact with someone with measles will contract it. Measles can be contracted through direct contact with infected people, or through airborne droplets such as when infected people cough, sneeze, or exhale. 
Fortunately, the spread of measles has been curbed over time as more people have been vaccinated.
# Question 1
measles <- read.csv("~/ANT_109/Assignment_1/measles.csv")
q1Data <- measles[measles$year >= 1980,]
q1Data <- q1Data[order(q1Data$year, decreasing=FALSE),]
barplot(q1Data$measles.cases/1000, las=1, main="Annual Measles Cases Between 1980 and 2017", names.arg=q1Data$year, col="red", ylab="Measles Cases (thousands)", xlab="Year", space=0.5)
axis(side=1, tick=TRUE, at=NULL, line=NA, labels=FALSE)

The graph above is a bar plot showing the number of global annual measles cases for each year from 1980 to 2017. The highest number of recorded measles cases within this time frame is 4,078,455 cases in 1981, while the lowest number of cases is 
132,328 cases in 2016. Astonishingly, the number of measles cases decreased by a factor of 30 over this period of 37 years. There is a downwards exponential trend of cases over time, which is encouraging because it shows that our improving 
technology and procedures are decreasing the infectivity of the pathogen.

Question 2

As an extremely contagious disease, one person infected with measles who is exhibiting conditions of coughing and sneezing 
is able to infect nine out of every ten susceptible (especially non-vaccinated) people that they come into contact with. 
However, developments in measles vaccines as well as increasing vaccination coverage worldwide have cut down on the spread 
of measles. According to the World Health Organization, measles was one of the first diseases targeted for a global 
immunization program in 1974. After the measles vaccine was created, it took time to manufacture and distribute, but over 
time most of the world was vaccinated against measles.
# Question 2
library(plotly)
measles <- read.csv("~/ANT_109/Assignment_1/measles.csv")
q2Data <- measles[measles$year >= 1985 & measles$year <= 2005,]
q2Data <- q2Data[order(q2Data$year, decreasing=FALSE),]

total <- plot_ly(x=q2Data$vaccination.coverage, 
                 y=q2Data$measles.cases/1000,
                 type="scatter",
                 mode="markers"
                )
total <- total %>% layout(xaxis=list(title="<b>Vaccination Coverage (%)</b>"),
                          yaxis=list(title="<b>Annual Measles Cases (thousands)</b>"),
                          title = "<b>Vaccination Coverage vs Measles Cases (c. 1985-2005)</b>",
                          plot_bgcolor="lightgrey"
                        )
    total
Vaccinations have become crucial in curbing the transmission of measles over time. The graph above displays the inverse 
relationship between the percent of vaccination coverage worldwide and the number of annual measles cases worldwide between 1985 and 2005: as vaccination coverage increases, the number of annual measles cases decreases. There is a large cluster of data points at the bottom right corner of the graph where there is a larger vaccination coverage and lower measles cases, 
which suggests that there are more years at which vaccination coverage was between 70% and 75%, with annual measles cases 
hovering around 750,000: a far cry from the peak number of measles cases of about 4 million cases.    

Question 3

# Question 3 
library(plotly)
measles <- read.csv("~/ANT_109/Assignment_1/measles.csv")
q3Data <- measles[measles$year >= 1980 & measles$year <= 2017,]
q3Data <- q3Data[order(q3Data$year, decreasing=FALSE),]

total <- plot_ly()
total <- total %>% add_trace(x=q3Data$year, y=q3Data$measles.cases/1000, name="<b>Measles Cases (thousands)</b>", type="bar", marker=list(color="chocolate"))

coverage <- list(
    tickfont = list(color = "blue"),
    titlefont = list(color = "blue"),
    gridcolor="aquamarine",
    overlaying = "y",
    side = "right",
    title = "<b>Vaccination Coverage (%)</b>"
    )

total <- total %>% add_trace(x=q3Data$year, y=q3Data$vaccination.coverage, name="<b>Vaccination Coverage (%)</b>", yaxis="y2",mode="lines+markers", type="scatter", marker=list(color="blue"), line=list(color="blue"))

total <- total %>% layout(
    title = "<b>Vaccination Coverage and Annual Measle Cases from 1980 to 2017</b>",
    yaxis2=coverage,
    xaxis=list(title="<b>Year </b>"),
    yaxis= list(title="<b>Measles Cases (thousands)</b>",
                tickfont = list(color = "chocolate"),
                titlefont = list(color = "chocolate")
                )
    ) %>% layout(
        plot_bgcolor="lightgrey",
        xaxis = list(zerolinecolor = "brown",
                     zerolinewidth = 2, 
                     gridcolor = "black"),
        yaxis = list(zerolinecolor = "brown",
                     zerolinewidth = 2, 
                     gridcolor = "brown"))
total