This assignment presents three visualizations based on the CES-D 8 depression scale in Austria (ESS Round 11). Each plot follows the structure required: a clear research message, visual plan, and code implementation using ggplot2.
The goal is to explore:
The distribution of depressive symptoms
Gender differences in clinical depression rates
The influence of key predictors using a logistic regression model
ess = read_sav("C:/Users/Alaina/OneDrive/Desktop/ESS11.sav")
ess_austria=ess[ess$cntry=="AT",]
# Recode function: 1–4 to 0–3 scale
recode_to_03= function(x) {
ifelse(is.na(x), NA,
ifelse(x == 1, 0,
ifelse(x == 2, 1,
ifelse(x == 3, 2,
ifelse(x == 4, 3, NA)))))
}
# Recode and reverse where needed
ess_austria$fltdpr_r = recode_to_03(ess_austria$fltdpr)
ess_austria$fltlnl_r = recode_to_03(ess_austria$fltlnl)
ess_austria$cldgng_r = recode_to_03(ess_austria$cldgng)
ess_austria$wrhpp_r = 3 - recode_to_03(ess_austria$wrhpp) # reverse
ess_austria$fltsd_r = recode_to_03(ess_austria$fltsd)
ess_austria$enjlf_r = 3 - recode_to_03(ess_austria$enjlf) # reverse
ess_austria$flteeff_r = recode_to_03(ess_austria$flteeff)
ess_austria$slprl_r = recode_to_03(ess_austria$slprl)
# Calculate CES-D 8 depression score
ess_austria$cesd8 = ess_austria$fltdpr_r + ess_austria$fltlnl_r + ess_austria$cldgng_r +
ess_austria$wrhpp_r + ess_austria$fltsd_r + ess_austria$enjlf_r +
ess_austria$flteeff_r + ess_austria$slprl_r
# Cap maximum value at 23
ess_austria$cesd8 = pmin(ess_austria$cesd8, 23)
# Reverse positively worded items
ess_austria$wrhpp_r = 6 - ess_austria$wrhpp
ess_austria$enjlf_r = 6 - ess_austria$enjlf
# Calculate CES-D 8 score using correctly oriented items
ess_austria$cesd8= ess_austria$fltdpr + ess_austria$fltlnl + ess_austria$cldgng +
ess_austria$wrhpp_r + ess_austria$fltsd + ess_austria$enjlf_r +
ess_austria$flteeff + ess_austria$slprl
# Define binary variable for clinical depression (cutoff >= 9)
ess_austria$clin_depression <- ifelse(ess_austria$cesd8 >= 9, 1, 0)
ggplot(ess_austria, aes(x = cesd8)) +
geom_histogram(binwidth = 1, fill = "deeppink", color = "black") +
geom_vline(xintercept = 9, linetype = "dashed", color = "orange") +
labs(title = "Distribution of CES-D 8 Depression Scores",
subtitle = "orange line = clinical cutoff (≥9)",
x = "Depression Score",
y = "Number of Participants",
caption = "Alaina") +
theme_minimal()
## Warning: Removed 33 rows containing non-finite outside the scale range
## (`stat_bin()`).
# Clean and label gender + depression variables
ess_gender= ess_austria[complete.cases(ess_austria[, c("gndr", "clin_depression", "cesd8")]), ]
# Apply readable labels
ess_gender$gndr=factor(ess_gender$gndr,
levels = c(1, 2),
labels = c("Male", "Female"))
ess_gender$clin_depression= factor(ess_gender$clin_depression,
levels = c(0, 1),
labels = c("No", "Yes"))
dftmp =data.frame(
meany = as.numeric(by(ess_gender$cesd8, ess_gender$gndr, mean, na.rm = TRUE)),
sdy = as.numeric(by(ess_gender$cesd8, ess_gender$gndr, sd, na.rm = TRUE)),
gndr = levels(ess_gender$gndr)
)
# Plot: Mean + SD
ggplot(dftmp, aes(y = meany, x = gndr)) +
geom_errorbar(aes(ymin = meany - sdy, ymax = meany + sdy), color = "#333", width = 0.1) +
geom_point(color = "steelblue", size = 4) +
labs(title = "Mean CES-D 8 Score by Gender",
subtitle = "With ±1 SD error bars",
x = "Gender",
y = "Mean Depression Score",
caption = "Alaina") +
theme_minimal()
These graphics provide insight into the distribution of depression, gender differences in clinical depression, and the strongest predictors of depression among Austrian respondents in ESS Round 11.