-- Leo's gemini proxy
-- Connecting to gemlog.blue:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
Prevalence, "Share (%) of population suffering from drug use disorders By Age. "
Install: R language, RTools40 and RStudio (see link below)
Packages: GGPLot2, dplyr, janitor.
Download code and data from Github.com (see link below).
Move R code and data to working directory
library(ggplot2) library(scales) library(dplyr) library(readr) library(tidyr) library(janitor) rm(list=ls()) df <- read_csv("./prevalence-of-drug-use-disorders-by-age.csv") %>% filter(Code =="USA") %>% select(-Entity,-Code) colnames(df) <- c("Year","age_14","age_19","age_24", "age_29","age_34","all_age_percent","age5_14","age15_49", "age_70","standard_percent") df <- df %>% select(Year,age_14,age_19,age_24,age_29,age_34,age5_14, age15_49,age_70,all_age_percent,standard_percent) * Two Quick Plots: ggplot(df) + geom_line(aes(x=Year,y=all_age_percent)) + labs(title="All Age Precent") ggplot(df) + geom_line(aes(x=Year,y=standard_percent)) + labs(title="Age-standardized Percent") + * User dplyr pivot_longer to re-arrange longer age_longer <- pivot_longer(df,cols=age_14:standard_percent) age_longer$Percent <- age_longer$value /100 head(age_longer) * Age 5-14 and Age 15-49 age_longer %>% filter(name=="age5_14") %>% ggplot() + geom_line(aes(x=Year,y=Percent,col=name)) + labs(title="Drug by Year for Ages 5 - 14", y="Percent of Drug Use") + scale_y_continuous(labels=percent) age_longer %>% filter(name=="age15_49") %>% ggplot() + geom_line(aes(x=Year,y=Percent,col=name)) + labs(title="Drug by Year for Ages 15 - 49",y="Percent of Drug Use") + scale_y_continuous(labels=percent) * Percent by Age Groups: 10 - 70 short_list <-age_longer %>% filter(! (name %in% c("age15_49","all_age_percent","standard_percent","age5_14"))) ggplot(short_list) + geom_line(aes(x=Year,y=Percent,col=name)) + scale_y_continuous(labels=percent) + guides(color = guide_legend(override.aes = list(size = 2))) + labs(title="USA Prevalence of Drug Use Disorders by Age")
-- Response ended
-- Page fetched on Fri Apr 26 12:10:12 2024