Final Project: [Sexual Education, Contraceptive Use, & Pregnancy Risk]
Author
Belen Zemas & Amel Attalla
Published
June 26, 2025
Introduction
In this project we aim to examine the relationship between the types of sexual health education that are taught in the United States, contraceptive knowledge and risk of unplanned pregnancies, as well as how that knowledge is applied to real life. What constitutes appropriate and effective sexual education continues to be an increasingly debated topic, we aim to shed light on how different approaches-such as abstinence-only vs. contraceptive focused curricula may correlate with public health outcomes. For this project we have decided to create visualizations that focus on these three questions:
1. How does sex education type influence perceptions of pregnancy risk?
2. How does sex education type influence the method of contraceptive used?
3. How do sexual education type, perceived pregnancy risk, and contraceptive method interrelate in shaping reproductive decision-making?
Data
We sourced our raw data set from the ICPSR website. Some of the key variables we are focusing on after cleaning the raw data are: birth control knowledge, risk of unplanned pregnancy, and types of sexual health education received. Cleaning the data set mainly consisted of narrowing down the variables from 340 to 12 keeping only the variables that we felt were relevant to our project. The steps taken to wrangle and clean the original data set can be seen in it’s entirety in the code below.
Visualization 1: Sexual Health Education and Risk of Unintended Pregnancy (Stacked Bar Chart)
This plot displays the percentage of participants who perceive themselves to be at risk of unintended pregnancy, grouped by the type of sexual education they received. Across all sex ed types, the majority of participants report being at risk.Those who received no sex ed or don’t know report lower risk perception than those with abstinence-based education, suggesting that the type of education may shape perceived vulnerability. Something interesting to note is that abstinence-only group had the highest risk at 77.3%.
Code
# your code herelibrary(ggplot2)library(viridis)library(dplyr)clean_fogzone <-readRDS("data/clean_fogzone.rds")clean_fogzone_factors <- clean_fogzone %>%mutate(abstonly =factor( abstonly,levels =c("No sex ed/ don't know", "Abstinence Only", "Abstinence Focused", "Contraceptive Focused") ),riskr =factor(riskr, levels =c("No", "Yes")) )percent_data <- clean_fogzone_factors %>%group_by(abstonly, riskr) %>%summarise(n=n(), .groups="drop") %>%group_by(abstonly) %>%mutate(pct = n /sum(n) *100)ggplot(percent_data, aes(x = abstonly, y = pct, fill = riskr)) +geom_bar(stat ="identity", position =position_dodge(width =0.9)) +geom_text(aes(label =paste0(round(pct, 1), "%")),position =position_dodge(width =0.9),vjust =-0.4,size =3.5 ) +scale_fill_viridis_d(option="D",name ="At Risk?",labels =c("No", "Yes") ) +labs(title ="Sexual Health Education and Risk of Unintended Pregnancy",x ="Type of Sexual Health Education Recived",y ="Percentage of Participants" ) +ylim(0,100) +theme_minimal(base_size =12) +theme(plot.margin =margin(50, 30, 30, 30), # Adjust all margins (top, right, bottom, left)axis.text.x =element_text(angle =20, hjust =1, face ="bold", size =10),axis.text.y =element_text(face ="bold"),plot.title =element_text(face ="bold"),legend.position ="top" )
Visualization 2: Contraceptive Methods by Type of Sexual Education (Faceted Bar Chart)
This plot displays the contraceptive methods used by participants grouped by their type of sex ed. More comprehensive sex ed (Contraceptive Focused) is associated with greater use of effective methods like condoms or hormonal contraception.No Method and No Sex (Last 12 Mo) appear across all education types, but tend to be more frequent in less comprehensive or absent education categories.
Code
# Step 1: Clean and relabel variablescontraceptive_data <- clean_fogzone_factors %>%filter(!is.na(Current_most_effective_method)) %>%mutate(method_grouped =case_when( Current_most_effective_method %in%c("no method - likely at risk", "no method - risk unknown") ~"No method", Current_most_effective_method %in%c("withdrawl/NFP", "other/unknown") ~"Other/Unknown/Withdrawal",TRUE~ Current_most_effective_method ),# Capitalize for better displaymethod_grouped =recode(method_grouped,"condoms"="Condoms","hormonal + condoms"="Hormonal + Condoms","hormonal alone"="Hormonal","long-acting + condom"="LARC + Condoms","long-acting alone"="LARC","No method"="No Method","no sex ever/ last 12 mo"="No Sex (Last 12 Mo)","Other/Unknown/Withdrawal"="Other/Unknown/Withdrawal" ),method_grouped =factor(method_grouped),# Add line breaks in abstonly for better facet titlesabstonly =recode(abstonly,"No sex ed/ don't know"="No Sex Ed/\nDon't know","Abstinence Only"="Abstinence\nOnly","Abstinence Focused"="Abstinence\nFocused","Contraceptive Focused"="Contraceptive\nFocused" ) )# Step 2: Create percentage summarycontraceptive_summary <- contraceptive_data %>%group_by(abstonly, method_grouped) %>%summarise(n =n(), .groups ="drop") %>%group_by(abstonly) %>%mutate(pct = n /sum(n) *100)# Step 3: Plot with vertical bars and improved facet layoutggplot(contraceptive_summary, aes(x = method_grouped, y = pct, fill = method_grouped)) +geom_bar(stat ="identity") +scale_fill_viridis_d(name ="Contraceptive Method",option ="C" ) +labs(title ="Contraceptive Methods by Type of Sexual Education",x ="Contraceptive Method",y ="Percentage of Participants" ) +ylim(0, 40) +facet_wrap(~abstonly, nrow =1, scales ="free_x") +theme_minimal(base_size =14) +theme(plot.margin =margin(t =60, r =30, b =30, l =30),axis.text.x =element_blank(),axis.ticks.x =element_blank(),axis.text.y =element_text(face ="bold"),plot.title =element_text(face ="bold", hjust =0.5, size =12),strip.text =element_text(face ="bold", size =8),legend.position ="right",legend.title =element_text(face ="bold", size =8),legend.text =element_text(size =8) )
Visualization 3: Flow of Sex Ed → Risk Perception → Contraceptive Method
This diagram shows the flow of participants through the type of sex ed they receive, whether they perceive pregnancy risk, and their chosen contraceptive method. Contraceptive-Focused more frequently flows into more effective methods such as condom use, hormonal, or both combined, where abstinence-only flows more into no method.
Code
library(tidyverse)library(ggplot2)library(ggalluvial)library(dplyr)sankey_data <- contraceptive_data %>%filter(!is.na(riskr), !is.na(abstonly), !is.na(method_grouped)) %>%count(abstonly, riskr, method_grouped) ggplot(sankey_data,aes(axis1 = abstonly, axis2 = riskr, axis3 = method_grouped,y = n)) +geom_alluvium(aes(fill = method_grouped), width =0.3, alpha=0.8) +geom_stratum(width =0.1,fill ="gray90",color ="black") +geom_text(stat ="stratum",aes(label =after_stat(stratum)),size =3, check_overlap =TRUE, na.rm =TRUE,label_axis3 =NULL ) +scale_x_discrete(limits =c("Sex Ed Type", "Perceived Risk", "Contraceptive Method"),expand =c(0.05, 0.05)) +scale_fill_viridis_d(option ="C", name ="Contraceptive Method") +labs(title ="Flow from Sexual Education to Risk Perception to Contraceptive Behavior",y ="Number of Participants" ) +theme_minimal(base_size =14) +theme(plot.title =element_text(face ="bold", hjust =0.5),axis.text.y =element_blank(),axis.ticks =element_blank(),legend.title =element_text(size =8, face ="bold"),legend.text =element_text(size =7),legend.key.size =unit(0.4, "cm"), legend.spacing.y =unit(0.2, "cm"), legend.position ="right",plot.margin =margin(t =20, r =30, b =20, l =30) )
OR Shiny app: [Title Here]
If you choose to create a Shiny app, describe the app’s purpose and functionality. Save your code inside the shiny-app/ folder, replace the URL below with your app’s URL
Summarize your key findings. What do your visualizations reveal?
Limitations
Discuss any data quality or design limitations.
Conclusion
Wrap up your project with a takeaway message or next steps.
References
Include any references to data sources, packages, or literature you used. If your visualization design is inspired by someone else’s work, cite those too.