Some preparation:
ESS <- transmute(ESS, # Recode several variables & keep only the recoded ones (i.e., transmute vs mutate). #<<
idno = zap_labels(idno),
# Make the following variables factors:
cntry = as_factor(cntry),
gndr = as_factor(gndr),
facntr = as_factor(facntr),
mocntr = as_factor(mocntr),
# Make the following variables numeric:
imbgeco = max(imbgeco, na.rm = TRUE) - zap_labels(imbgeco), # Also turn scale around.
imueclt = max(imueclt, na.rm = TRUE) - zap_labels(imueclt), # Also turn scale around.
imwbcnt = max(imwbcnt, na.rm = TRUE) - zap_labels(imwbcnt), # Also turn scale around.
# Homophobia #<<
freehms = as_factor(freehms),
hmsfmlsh = as_factor(hmsfmlsh),
hmsacld = as_factor(hmsacld),
agea = zap_labels(agea),
pspwght = zap_labels(pspwght),
eduyrs = zap_labels(eduyrs))
ESS <- dplyr::filter(ESS,
# Now keep respondents of immigrant origin!
# facntr == "Yes" & mocntr == "Yes" & # Keep respondents of immigrant origin #<<
# Only respondents from direct neighbors of Denmark:
(cntry == "Denmark" | cntry == "Germany" | cntry == "Sweden" | cntry == "Norway")
)
# Casewise deletion of missing values
ESS <- drop_na(ESS)
cntry
. Which country (Denmark, Germany, or Sweden) has the largest number of observations?
labs()
(i.e., learn it from the reference page of ggplot2).ggplot(data = ESS) +
geom_bar(aes(x = cntry, weight = pspwght)) +
labs(x = "Country of interview")
agea
. Across all four countries, are there more or less than 20 respondents who are older than 100? ggplot(data = ESS) +
geom_histogram(aes(x = agea, weight = pspwght)) +
labs(x = "Age")
ggplot(data = ESS, mapping = aes(x = hmsacld, weight = pspwght)) +
geom_bar() +
facet_grid(. ~ gndr) +
labs(x = "Gay and lesbian couples should have right to adopt children") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplot(data = ESS, mapping = aes(x = hmsacld, weight = pspwght)) +
geom_bar() +
facet_grid(cntry ~ gndr, scales = "free_y") +
labs(x = "Gay and lesbian couples should have right to adopt children") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ESS <- import_rounds(rounds = 9, ess_email = "YOUR-EMAIL", format = "spss")
ESS <- transmute(ESS, # Recode several variables & keep only the recoded ones (i.e., transmute vs mutate). #<<
idno = zap_labels(idno),
# Make the following variables factors:
cntry = as_factor(cntry),
gndr = as_factor(gndr),
facntr = as_factor(facntr),
mocntr = as_factor(mocntr),
# Make the following variables numeric:
imbgeco = max(imbgeco, na.rm = TRUE) - zap_labels(imbgeco), # Also turn scale around.
imueclt = max(imueclt, na.rm = TRUE) - zap_labels(imueclt), # Also turn scale around.
imwbcnt = max(imwbcnt, na.rm = TRUE) - zap_labels(imwbcnt), # Also turn scale around.
# Homophobia #<<
freehms = as_factor(freehms),
hmsfmlsh = as_factor(hmsfmlsh),
hmsacld = as_factor(hmsacld),
agea = zap_labels(agea),
pspwght = zap_labels(pspwght),
eduyrs = zap_labels(eduyrs))
# Some case selection, now also including: France!
ESS <- dplyr::filter(ESS, # Denmark, Sweden, Norway, Germany, and France.
cntry == "Denmark" | cntry == "Sweden" |
cntry == "Norway" | cntry == "Germany" | cntry == "France")
# Casewise deletion of missing values
ESS <- drop_na(ESS)
ggplot(data = ESS) +
geom_boxplot(aes(y = as.numeric(hmsfmlsh), fill = cntry, weight = pspwght)) +
labs(y = "Not Ashamed if close family member \n was gay or lesbian")
ggplot(data = ESS, mapping = aes(y = hmsfmlsh, x = cntry)) +
geom_jitter(alpha = 0.1, aes(size = pspwght)) +
geom_violin(mapping = aes(fill = cntry, weight = pspwght),
alpha = 0.6, draw_quantiles = c(0.25, 0.5, 0.75)) +
labs(y = "Not Ashamed if close family member \n was gay or lesbian",
x = "Country of interview")
hmsfmlsh
and years of education. Does it change the main conclusion/insight of that figure? ESS <- mutate(ESS,
eduyrs_rec = case_when(
eduyrs < 10 ~ as.numeric(NA), # Eduyears smaller 10 ~ Missing
eduyrs > 20 ~ 20, # Eduyears larger 20 ~ 20
TRUE ~ eduyrs) # Leave all others as is.
)
The old one:
ggplot(data = ESS, mapping = aes(y = hmsfmlsh, x = eduyrs, weight = pspwght)) +
geom_point(aes(size = pspwght), alpha = 0.1) +
geom_smooth() +
labs(y = "Not Ashamed if close family member \n was gay or lesbian",
x = "Years of education")
The new one:
ggplot(data = ESS, mapping = aes(y = hmsfmlsh, x = eduyrs_rec, weight = pspwght)) +
geom_point(aes(size = pspwght), alpha = 0.1) +
geom_smooth() +
labs(y = "Not Ashamed if close family member \n was gay or lesbian",
x = "Years of education")