Overview

This file contains a set of tasks that you need to complete in R for the lab assignment. The tasks may require you to add a code chuck, type code into a chunk, and/or execute code. Don’t forget that you need to acknowledge if you used any resources beyond class materials or got help to complete the assignment.

Additional information, include examples and code, about this assignment can be found in the file “VisualizingDistributionsTutorial.html”.

The data set you will use is different than the one used in the instructions. Pay attention to the differences in the Excel files’ names, any variable names, or object names. You will need to adjust your code accordingly.

Once you have completed the assignment, you will need to knit this R Markdown file to produce an .html file. You will then need to upload the .html file and this .Rmd file to AsULearn.

1. Add your Name and the Date

The first thing you need to do in this file is to add your name and date in the lines underneath this document’s title (see the code in lines 9 and 10).

2. Identify and Set Your Working Directory

You need to identify and set your working directory in this section. If you are working in the cloud version of RStudio, enter a note here to tell us that you did not need to change the working directory because you are working in the cloud.

getwd()
## [1] "/Users/summersimpson/Downloads/VisualizingDistributionsFall2025 2"
setwd("/Users/summersimpson/Downloads/VisualizingDistributionsFall2025 2")

3. Installing and Loading Packages and Data Set

You load the packages and data set you’ll use for the lab assignment in this section. In this lab we will use the packages: dplyr, tidyverse, forcats, ggplot2, and openxlsx.

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
library("tidyverse")
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.2     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.3.0
## ✔ purrr     1.1.0     ✔ tidyr     1.3.1
## ── 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("openxlsx")
library("forcats")
library("ggplot2")
BBQData_Assignment8 <- read.xlsx("BBQData_Assignment8.xlsx")
names(BBQData_Assignment8)
##  [1] "Observation"        "Sex"                "Age"               
##  [4] "Hometown"           "Favorite.Meat"      "Favorite.Sauce"    
##  [7] "Sweetness"          "Favorite.Side"      "Restaurant.City"   
## [10] "Restaurant.Name"    "Minutes.Driving"    "Sandwich.Price"    
## [13] "Dinner.Plate.Price" "Ribs.Price"

4. Histogram of Price for Plate of Ribs

Create a histogram showing the distribution of the variable measuring the price someone would pay for a plate of ribs.

ggplot(BBQData_Assignment8,
       aes(x=Dinner.Plate.Price)) +
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Histogram of Dinner Plate Price with customizations
ggplot(BBQData_Assignment8, 
       aes(x = Dinner.Plate.Price)) +
  geom_histogram(
    bins = 15,             
    fill = "magenta",      
    color = "black"         
  ) +
  labs(
    x = "Dinner Plate Price",   
    y = "Frequency"             
  ) +
  theme_classic()

5. Histogram of Minutes Driving

Create a histogram showing the distribution of the variable measuring the minutes someone is willing to drive for BBQ.

ggplot(BBQData_Assignment8, 
       aes(x = Minutes.Driving)) +
  geom_histogram(
    bins = 25,             
    fill = "violet",       
    color = "black"        
  ) +
  labs(
    x = "Minutes Willing to Drive", 
    y = "Frequency"                 
  ) +
  theme_classic() 

# 6. Density Plot of Minutes Driving Create a density plot showing the distribution of the variable measuring minutes someone is willing to drive for BBQ.

ggplot(BBQData_Assignment8, 
       aes(x = Minutes.Driving)) +
  geom_density(
    color = "lightblue4",       
    fill = "lightblue1",        
    linetype = "twodash",       
    linewidth = 1               
  ) +
  geom_vline(
    aes(xintercept = mean(Minutes.Driving, na.rm = TRUE)), 
    color = "black", 
    linetype = "dashed", 
    linewidth = 1
  ) +
  labs(
    x = "Minutes Willing to Drive",   
    y = "Density"                    
  ) +
  theme_classic() 

# 7. Density Plot of Price for Pulled Pork Sandwich Create a density plot showing the distribution of the variable measuring the price someone is willing to pay for a pulled pork sandwich.

ggplot(BBQData_Assignment8, 
       aes(x = Sandwich.Price)) +
  geom_density(
    color = "springgreen4",     
    fill = "springgreen1",      
    linetype = "longdash",      
    linewidth = 1
  ) +
  geom_vline(
    aes(xintercept = mean(Sandwich.Price, na.rm = TRUE)),  # vertical line at mean
    color = "black", 
    linetype = "dashed", 
    linewidth = 1
  ) +
  labs(
    x = "Price Willing to Pay for Pulled Pork Sandwich",  # capitalized and descriptive x-axis label
    y = "Density"                                         # capitalized y-axis label
  ) +
  theme_classic() 

8. Box-and-Whisker Plot of Pulled Pork Sandwich

Create a box-and-whisker plot of the variable measuring the price someone is willing to pay for a pulled pork sandwich.

ggplot(BBQData_Assignment8, 
       aes(y = Sandwich.Price)) +     
  geom_boxplot(
    fill = "azure1",                     
    color = "blue",                      
    outlier.colour = "darkcyan",        
    outlier.shape = 8                    
  ) +
  coord_flip() +                         
  labs(
    y = "Price Willing to Pay for Pulled Pork Sandwich",  
    x = " "                                               
  ) +
  theme_classic() +                     
  theme(
    axis.text.y = element_text(size = 11),
    axis.text.x = element_text(size = 11),
    axis.title.y = element_text(size = 12, face = "bold")
  )

9. Box-and-Wisker Plot of Minutes Willing to Drive

Create a box-and-whisker plot of the variable measuring the minutes someone is willing to drive for BBQ.

ggplot(BBQData_Assignment8, 
       aes(x = "", y = Minutes.Driving)) +   
  geom_boxplot(
    fill = "lightsteelblue1",                
    color = "lightsteelblue4",               
    outlier.colour = "mediumpurple4",        
    outlier.shape = 5                        
  ) +
  labs(
    x = " ",                                 
    y = "Minutes Willing to Drive for BBQ"   
  ) +
  theme_classic() +                           
  theme(
    axis.text.x = element_blank(),           
    axis.text.y = element_text(size = 11),
    axis.title.y = element_text(size = 12, face = "bold")
  )

10. Did you receive help?

Enter the names of anyone one that assisted you with completing this lab. If no one helped you complete the assignment, just type out that no one helped you No one helped me but I used Chat GPT to help me figure out an error code when trying to create no background color.

11. Did you provide anyone help with completing this lab?

Enter the names of anyone that you assisted with completing this lab. If you did not help anyone, then just type out that you didn’t help anyone. I didn’t help anyone

12. Publish Document

Click the “Knit” button to publish your work as an html document. This document or file will appear in your working directory. You will need to upload both this RMarkdown file and the html file it produces to AsU Learn to get all of the lab points for this week.