💾 Archived View for gemlog.blue › users › cariboudatascience › 1613433336.gmi captured on 2023-04-26 at 14:56:29. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2021-12-04)
-=-=-=-=-=-=-
Prevalence of Drug Use Disorders by age(Part 2)
- Prevalence, "Share (%) of population suffering from drug use disorders By Age. "
Software required to recreate plot:
- 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
Youtube
Gemini Browser
Caribou Data Science(Capsule)
Code:
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)
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_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")
Plot Gallery
Plot of Ages 5 - 15 Years
PLot of Ages 15-49 Years
Prevalence by Age
Standard Percent (all ages / all sex)
Resources:
R Code, data
R Language and Rtools40 (click and "base" and "Rtools")
Download and install RStudio