Skip to content

Instantly share code, notes, and snippets.

@rohit-gupta
Last active November 16, 2018 15:54
Show Gist options
  • Save rohit-gupta/3e5a7cd843359442d097ae86b38581da to your computer and use it in GitHub Desktop.
Save rohit-gupta/3e5a7cd843359442d097ae86b38581da to your computer and use it in GitHub Desktop.
CDC_High_School_YRBS_Plot.R
library(readr)
library(tidyr)
library(ggplot2)
CDC_YRBS_eversex <- read_delim("CDC_YRBS_eversex.tsv",
"\t", escape_double = FALSE, na = "N/A",
trim_ws = TRUE)
CDC_YRBS_eversex$Grade <- factor(CDC_YRBS_eversex$Grade, levels=c("9th","10th", "11th", "12th"))
latest_year_plot <- ggplot(CDC_YRBS_eversex, aes(x=Race, y=`2017`)) + geom_col(aes(fill = Grade), position = "dodge")
latest_year_plot
cdc_tall <- gather(CDC_YRBS_eversex, year, percent_ever_had_sex, Race, Grade)
facet_plot <- ggplot(cdc_tall, aes(year, percent_ever_had_sex)) + geom_point() + facet_grid(rows = vars(Race), vars(Grade))
facet_plot + labs(title ="Ever Had Sexual Intercourse by Grade and Race", subtitle="From CDC High School Youth Risk Behavior Survey")
Race Grade 1991 1993 1995 1997 1999 2001 2003 2005 2007 2009 2011 2013 2015 2017
Asian 9th N/A 14.2 N/A 6.5 6.8 N/A 22.1 N/A N/A 16.9 N/A N/A 5.0 5.0
Asian 10th 21.5 26.3 N/A 15.4 10.6 N/A N/A N/A 15.2 23.7 24.3 N/A N/A 10.5
Asian 11th 19.1 29.7 N/A 34.0 28.6 N/A N/A N/A N/A 30.5 33.7 27.2 25.9 20.0
Asian 12th N/A 50.3 N/A 38.3 52.0 39.3 N/A N/A 27.1 24.7 43.7 32.7 34.2 28.4
Black 9th 78.8 74.4 66.4 62.3 59.2 55.7 57.1 55.4 52.5 51.5 48.2 43.1 31.4 29.4
Black 10th 77.7 75.4 70.9 73.9 75.3 57.7 66.2 66.4 66.4 64.8 58.4 62.6 47.3 43.6
Black 11th 83.1 83.1 75.2 73.2 75.9 65.8 70.4 74.8 74.1 71.3 63.6 63.5 57.2 53.7
Black 12th 85.8 84.8 81.4 80.8 79.7 68.5 83.4 80.0 81.8 79.7 73.9 77.4 63.3 60.9
Hispanic 9th 42.0 44.2 48.5 41.8 42.5 35.9 36.0 40.5 39.7 37.9 36.8 31.6 25.9 21.3
Hispanic 10th 48.2 52.3 51.0 50.1 48.4 47.1 52.7 46.9 49.1 44.8 46.5 45.8 36.0 38.9
Hispanic 11th 59.2 59.1 63.9 54.5 59.3 57.5 60.2 55.0 58.1 56.2 56.0 56.7 52.2 51.9
Hispanic 12th 62.3 66.3 67.4 62.2 71.6 63.1 65.9 69.7 70.5 64.7 60.0 69.3 60.7 57.5
White 9th 31.1 31.1 28.4 30.7 34.4 30.1 25.3 29.4 25.8 24.9 27.3 26.5 21.3 17.7
White 10th 43.1 39.8 42.6 34.8 40.9 37.2 38.1 37.5 38.1 34.7 38.4 35.4 32.8 35.4
White 11th 60.7 53.6 56.1 47.3 47.8 49.5 49.6 47.3 52.3 49.8 50.5 53.0 47.8 45.3
White 12th 65.0 66.4 64.5 58.2 60.2 59.9 57.3 60.5 62.1 60.6 62.5 61.0 58.8 57.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment