library(tidyverse)
library(haven)
library(ggthemes)
library(scales)
ggplot_scale <- c("navyblue", "tan4", "chartreuse4", "blueviolet", "blue", "deeppink4", "goldenrod", "violetred", "turquoise2", "lightgreen", "lightpink1", "yellow1", "slategrey", "peachpuff2", "mediumorchid4", "mediumspringgreen", "tomato")
wvs <- read_sav("data/world-values-survey.sav")
wvs_mexico <- wvs %>% filter(v1 == 484)
# make an id row for plotting
wvs_mexico$id <- seq_len(nrow(wvs_mexico))
wvs_mexico$respondents <- "respondents"
# 1 = Male; 2 = Female
wvs_mexico <- wvs_mexico %>%
mutate(
gender = ifelse(v223 == 1, "Male", "Female")
)
median(wvs_mexico$v225, na.rm=TRUE)
## [1] 36
ggplot(wvs_mexico %>% filter(!is.na(v225))) +
geom_density(aes(as.numeric(v225), colour=gender)) +
theme_classic() +
labs(x="Age", y="Density",
title="World Values Survey - Mexico - Age Distribution") +
scale_color_manual(values=ggplot_scale)
ggsave("fig-age-density.png")
## Saving 7 x 5 in image
pct_female <- as.numeric(round(count(wvs_mexico %>% filter(gender=="Female")) / nrow(wvs_mexico), 2)) * 100
pct_male <- as.numeric(round(count(wvs_mexico %>% filter(gender=="Male")) / nrow(wvs_mexico), 2)) * 100
paste("Female %:", pct_female, "Male %:", pct_male)
## [1] "Female %: 55 Male %: 45"
ggplot(wvs_mexico, mapping = aes(x = respondents)) +
geom_bar(aes(y = (..count..)/nrow(wvs_mexico),
fill = gender),
position="stack") +
theme_classic() +
scale_fill_manual(values=ggplot_scale) +
scale_y_continuous(labels=scales::percent) +
labs(y = "Percent of Respondents", x="")
ggsave("fig-gender-1.png")
## Saving 3 x 3 in image
ggplot(wvs_mexico, mapping = aes(x = gender)) +
geom_bar(aes(y = (..count..)/nrow(wvs_mexico),
fill = gender),
position="stack") +
theme_classic() +
scale_fill_manual(values=ggplot_scale) +
scale_y_continuous(labels=scales::percent, breaks=breaks_pretty()) +
labs(y = "Percent of Respondents", x="")
ggsave("fig-gender-2.png")
## Saving 3 x 3 in image
#v84
# agree, neither, disagree
men_job <- read_csv('
1,Agree
2,Neither
3,Disagree
', col_names=c("v84","v84_1"))
wvs_mexico <- wvs_mexico %>% full_join(men_job)
## Joining, by = "v84"
ggplot(wvs_mexico, mapping = aes(x = v84_1)) +
geom_bar(aes(y = (..count..)/nrow(wvs_mexico),
fill = gender)) +
theme_classic() +
scale_fill_manual(values=ggplot_scale) +
scale_y_continuous(labels=scales::percent,
breaks=breaks_pretty()) +
labs(y = "Percent of Respondents", x="",
title = "Men have more right to a job when scarce")
ggsave("fig-men-job.png")
## Saving 7 x 5 in image
#v114
boy_uni <- read_csv('
1,Strongly Agree
2,Agree
3,Disagree
4,Strongly Agree
', col_names=c("v114","v114_1"))
wvs_mexico <- wvs_mexico %>% full_join(boy_uni)
## Joining, by = "v114"
ggplot(wvs_mexico, mapping = aes(x = v114_1)) +
geom_bar(aes(y = (..count..)/nrow(wvs_mexico),
fill = gender)) +
theme_classic() +
scale_fill_manual(values=ggplot_scale) +
scale_y_continuous(labels=scales::percent,
breaks=breaks_pretty()) +
labs(y = "Percent of Respondents", x="",
title = "University is more important for a boy")
ggsave("fig-boy-uni.png")
## Saving 7 x 5 in image
#v211 == 1
ggplot(wvs_mexico, mapping = aes(x = as.factor(v211))) +
geom_bar(aes(y = (..count..)/nrow(wvs_mexico),
fill = gender)) +
theme_classic() +
scale_fill_manual(values=ggplot_scale) +
scale_y_continuous(labels=scales::percent,
breaks=breaks_pretty()) +
labs(y = "Percent of Respondents", x="",
title = "Is Divorce Justifiable? (1 is NEVER)")
ggsave("fig-divorce.png")
## Saving 7 x 5 in image
Can’t find this one, it says “V111” but that doesn’t match the sample questionnaire.
Can’t find this one, it says “V110” but that doesn’t match the sample questionnaire.
Already included in plots above.