Module #9

 3/10/2024


For this assignment, I chose a csv file containing data on cigarette consumption by state. 

I first read in the data: 

data <- read.csv("C:\\Users\\elisa_pazp940\\Downloads\\CigarettesB.csv")
head(data)

##   rownames   packs   price  income
## 1       AL 4.96213 0.20487 4.64039
## 2       AZ 4.66312 0.16640 4.68389
## 3       AR 5.10709 0.23406 4.59435
## 4       CA 4.50449 0.36399 4.88147
## 5       CT 4.66983 0.32149 5.09472
## 6       DE 5.04705 0.21929 4.87087

Then created a bar plot that shows cigarette consumption across different states:

# Bar plot: Cigarette packs consumption across different states
barplot(data$packs, names.arg = rownames(data), las = 2, col = "skyblue",
        main = "Cigarette Packs Consumption by State", xlab = "State", ylab = "Packs")



The bar plot works well for comparing the consumption levels of different states.


I also created a scatter plot showing the relationship between cigarette price and state income:

# Scatter plot: Relationship between cigarette price and income
plot(data$price, data$income, col = "red", xlab = "Price", ylab = "Income",
     main = "Cigarette Price vs Income", pch = 16)



The scatter plot showcases the correlation between pricing and income. 

And finally, a histogram showing the distribution of cigarette prices:

# Histogram: Distribution of cigarette prices
hist(data$price, col = "green", main = "Distribution of Cigarette Prices", xlab = "Price", ylab = "Frequency")



The histogram is good for visualization of pricing differences. 

Comments