#within the “adultTobaccoUseUS.csv” data set, I want to explore which form of tobacco product is the most commonly consumed among the US population. Dataset Source: Center for Disease Control (CDC)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(scales)
## Warning: package 'scales' was built under R version 4.3.3
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
Tobacco <- read_csv("adultTobaccoUseUS.cdc.csv")
## Rows: 273 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): LocationAbbrev, LocationDesc, Topic, Measure, Submeasure, Data Valu...
## dbl (2): Year, Imports Per Capita
## num (6): Population, Domestic, Imports, Total, Domestic Per Capita, Total Pe...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Tob <- Tobacco |> #Cleaning, removing un-needed variables
select(-LocationAbbrev, -LocationDesc, -Measure, -Domestic, -Imports, -`Domestic Per Capita`, -`Imports Per Capita`, -`Total Per Capita`)
AdultUse <- Tob |> #Setting X and Y axis, Naming Title, setting theme, number formatting
ggplot (aes(x = Year, y = Total, fill = Submeasure)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Adult Tobacco Use in the US", x = "Year", y = "Total Adult Users") +
theme_minimal()
options(scipen = 999)
print(AdultUse)
After importing the Tobacco use dataset, I needed to figure out which variables I was going to hold on to. To do so, I created a new object that would drop all of the variables that I thought wouldn’t be necessary. After that, I used ggplot to create a bar graph and set the x axis to the year and the y axis to the total adult users. The visualization shows a large decrease by the billions in the use of Cigars, combusitble, and loose tobacco over the decades. However other tobacco products have risen in usage, like snuff, pipe tobacco, and roll your own tobacco. One thing I had trouble with was formatting the y axis. If I could, I would have formatted the numbers to say “1b, 2b” and so forth. At first the numbers were being displayed as scientific notation, but thankfully I was able to at least format them into normal numbers.