Step 1

library(ggplot2)
library(gapminder)
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Step 2

drug_data<-read.csv("/Volumes/NO NAME/Data 333/SkillsDrill1Data.csv")

Step 3

head(drug_data)
##   marij_ever                        marij_month marij_year cocaine_ever
## 1          1        Used Marijuana Past 30 days          1            1
## 2          0 Did not use Marijuana Past 30 days          0            0
## 3          1 Did not use Marijuana Past 30 days          0            0
## 4          0 Did not use Marijuana Past 30 days          0            0
## 5          0 Did not use Marijuana Past 30 days          0            0
## 6          0 Did not use Marijuana Past 30 days          0            0
##                      cocaine_month cocaine_year crack_ever crack_month
## 1 Did not use Cocaine Past 30 days            0          1           0
## 2 Did not use Cocaine Past 30 days            0          0           0
## 3 Did not use Cocaine Past 30 days            0          0           0
## 4 Did not use Cocaine Past 30 days            0          0           0
## 5 Did not use Cocaine Past 30 days            0          0           0
## 6 Did not use Cocaine Past 30 days            0          0           0
##   crack_year heroin_ever heroin_month heroin_year hallucinogen_ever
## 1          0           0            0           0                 1
## 2          0           0            0           0                 0
## 3          0           0            0           0                 0
## 4          0           0            0           0                 0
## 5          0           0            0           0                 0
## 6          0           0            0           0                 0
##   hallucinogen_month hallucinogen_year inhalant_ever inhalant_month
## 1                  0                 1             0              0
## 2                  0                 0             0              0
## 3                  0                 0             0              0
## 4                  0                 0             0              0
## 5                  0                 0             0              0
## 6                  0                 0             0              0
##   inhalant_year meth_ever meth_month meth_year painrelieve_ever
## 1             0         0          0         0                0
## 2             0         0          0         0                0
## 3             0         0          0         0                0
## 4             0         0          0         0                0
## 5             0         0          0         0                0
## 6             0         0          0         0                0
##   painrelieve_month painrelieve_year tranq_ever tranq_month tranq_year
## 1                 0                0          0           0          0
## 2                 0                0          0           0          0
## 3                 0                0          0           0          0
## 4                 0                0          0           0          0
## 5                 0                0          0           0          0
## 6                 0                0          0           0          0
##   stimulant_ever stimulant_month stimulant_year sedative_ever sedative_month
## 1              0               0              0             0              0
## 2              0               0              0             0              0
## 3              0               0              0             0              0
## 4              0               0              0             0              0
## 5              0               0              0             0              0
## 6              0               0              0             0              0
##   sedative_year anydrugever                                       pharmamonth
## 1             0           1 Did not use Pharmaceutical Narcotics Past 30 days
## 2             0           0 Did not use Pharmaceutical Narcotics Past 30 days
## 3             0           1 Did not use Pharmaceutical Narcotics Past 30 days
## 4             0           0 Did not use Pharmaceutical Narcotics Past 30 days
## 5             0           0 Did not use Pharmaceutical Narcotics Past 30 days
## 6             0           0 Did not use Pharmaceutical Narcotics Past 30 days
##   nonpharmamonth nonpharmamonth_nomj anydrugmonth anydrugyear anydrugever_nomj
## 1              1                   0            1           1                1
## 2              0                   0            0           0                0
## 3              0                   0            0           0                0
## 4              0                   0            0           0                0
## 5              0                   0            0           0                0
## 6              0                   0            0           0                0
##   anydrugmonth_nomj anydrugyear_nomj countofdrugs_ever countofdrugs_month
## 1                 0                1                 4                  1
## 2                 0                0                 0                  0
## 3                 0                0                 1                  0
## 4                 0                0                 0                  0
## 5                 0                0                 0                  0
## 6                 0                0                 0                  0
##   countofdrugs_year SelectiveLeave SkipSick
## 1                 2              0        0
## 2                 0              0        0
## 3                 0              0        0
## 4                 0              0        0
## 5                 0              2        2
## 6                 0              0        0

Step 4

drug_data %>%
  select(cocaine_month,SelectiveLeave) %>%
  rename(DaysSkippedWork = SelectiveLeave) %>%
  filter(DaysSkippedWork<31) %>%
  summarize(meanDaysSkippedWork=mean(DaysSkippedWork))
##   meanDaysSkippedWork
## 1           0.3272463

Step 5

drug_data %>%
  select(cocaine_month,SelectiveLeave) %>%
  rename(DaysSkippedWork = SelectiveLeave) %>%
  filter(DaysSkippedWork<31) %>%
  group_by((cocaine_month)) %>%
  summarize(meanDaysSkippedWork=mean(DaysSkippedWork))
## # A tibble: 2 x 2
##   `(cocaine_month)`                meanDaysSkippedWork
## * <chr>                                          <dbl>
## 1 Did not use Cocaine Past 30 days               0.322
## 2 Used Cocaine Past 30 days                      0.85

Step 6

Step 7

drug_data %>%
  select(cocaine_month,SelectiveLeave) %>%
  rename(DaysSkippedWork = SelectiveLeave) %>%
  filter(DaysSkippedWork<31) %>%
  group_by(cocaine_month) %>%
  summarize(meanDaysSkippedWork=mean(DaysSkippedWork)) %>%
  ggplot() + 
  geom_col(aes(x=cocaine_month, y=meanDaysSkippedWork, fill=(meanDaysSkippedWork)))

Extra credit

drug_data %>%
  select(marij_month,SelectiveLeave) %>%
  rename(DaysSkippedWork = SelectiveLeave) %>%
  filter(DaysSkippedWork<31) %>%
  group_by(marij_month) %>%
  summarize(meanDaysSkippedWork=mean(DaysSkippedWork)) %>%
  ggplot() + 
  geom_col(aes(x=marij_month, y=meanDaysSkippedWork, fill=(meanDaysSkippedWork)))

Interpretation