Created
October 2, 2021 10:29
-
-
Save cavedave/6cf943e62c7bb78512c90e5f560f2c14 to your computer and use it in GitHub Desktop.
Do high trust countries have higher covid vaccination rates? Data from ourworldindata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trust <- read.csv("self-reported-trust-attitudes.csv",header=TRUE) | |
library(dplyr) | |
trust <- trust %>% | |
group_by(Entity) %>% | |
filter(Year == max(Year)) | |
vac <- read.csv("owid-covid-data (1).csv",header=TRUE) | |
vac<-vac %>% | |
dplyr::select(people_vaccinated_per_hundred, location, date) | |
library(lubridate) | |
vac$date<-ymd(vac$date) | |
vac<-na.omit(vac) | |
vac2 <- vac %>% | |
group_by(location) %>% | |
filter(people_vaccinated_per_hundred == max(people_vaccinated_per_hundred)) | |
#merge two datasets | |
joined_df <- merge(trust, vac2, by.x = "Entity", | |
by.y = "location", all.x = TRUE, all.y = FALSE) | |
joined_df<-rename(joined_df, Trust = Trust.in.others..World.Values.Survey..2014..) | |
joined_df<-rename(joined_df, Vaccinated = people_vaccinated_per_hundred) | |
#look for intereting countries | |
filter(joined_df, Trust > 65) | |
find<-dplyr::filter(joined_df, grepl("Armenia",Entity)) | |
#find blank entry and remove it | |
new_DF <- joined_df[rowSums(is.na(joined_df)) > 0,] | |
new_DF | |
joined_df = joined_df[-c(70),] | |
#get correltation | |
res <- cor(joined_df$Vaccinated,joined_df$Trust) | |
#graph | |
library(ggplot2) | |
p<-ggplot(joined_df, aes(x=Vaccinated, y=Trust)) + geom_point()+ geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) | |
p<-p + ggtitle("Countries Covid Vaccination Rates") + | |
xlab("% Vaccinated") + ylab("Trust") +theme_bw()+ theme(plot.title = element_text(hjust = 0.5)) | |
#add in labels | |
q<-p + annotate(geom="text", x=73, y=76, label="Norway", | |
color="black",size = 3.5) | |
q<-q + annotate(geom="text", x=60, y=40, label="USA", | |
color="black",size = 3.5) | |
q<-q + annotate(geom="text", x=71, y=28, label="UK", | |
color="black",size = 3.5) | |
q<-q + annotate(geom="text", x=70, y=0, label="data:ourworldindata\n cor:.45", | |
color="black",size = 2.5) | |
ggsave("TrustVaccines.png") | |
Author
cavedave
commented
Oct 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment