library(plotly)
measles <- read.csv("~/Desktop/GitHub/sts-109/hw1 /measles.csv")
#sorting the data base because the boxplot need it 
measles_sorted <- measles[order(measles$year), ]
barplot(names.arg= measles_sorted$year,
        height = measles_sorted$measles.cases/1000000,
        las = 1,
        col = "cyan4",
        ylab = "Measles Cases (per Million)",
        xlab = "Year",
        main = "Number of Measles Cases Per Year" )

The graph above shows the number of measles cases per year worldwide. We can observe a steady decline in measles cases throughout the years, which can be attributed to the measles vaccine introduced in 1963. There could be a variety of reasons for the reduction in numbers despite the availability of the vaccine. For instance, measles is airborne, so it takes time to be eliminated from the air. Additionally, the distribution of the vaccine has improved over time, resulting in more people receiving the vaccine then having lower amount of cases each year.

measles_sorted_year = measles_sorted[measles_sorted$year >= 1985 & measles_sorted$year<=2005,]
plot_ly(measles_sorted_year,y = ~measles.cases,x =~vaccination.coverage,type = 'scatter', mode = 'markers',
          text = ~paste("coverage:", vaccination.coverage, '\ncases(per million):', measles.cases/1000000,'\nyear:',year)) %>% 
         layout(title = 'Vaccination Coverage VS Measles Cases ',
         xaxis = list(title = 'Vaccination Coverage(%)'),
         yaxis = list(title = 'Measles Cases'))

Here is a graph showing the correlation between vaccination coverage and the number of measles cases between the years 1985 and 2005. We can see a strong negative correlation, especially between vaccination coverage levels of 68 to 75 percent, where the total number of measles cases decreases. Overall, the graph shows that the measles vaccine has had a positive effect in reducing the number of measles cases worldwide.

#https://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes

par(mar=c(5, 4, 4, 6) + 0.1)# shifts the graphs 

barplot(names.arg = measles_sorted$year,
        height = measles_sorted$measles.cases/1000000,
        las = 1,
        col = "cyan4",
        ylab = "Measles Cases (per Million)",
        xlab = "Year",
        main = "Number of Measles Cases Per Year vs Vaccination Coverage Rate ")


par(new=TRUE)

plot(measles_sorted$year,  measles_sorted$vaccination.coverage,type ="l",
     col = "red",lwd = 3,
     xaxt='n',yaxt='n',
     xlab ="",ylab = "")
mtext("Vaccination Coverage(%)",side=4,line=4, col = 'red')
axis(side =4)