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.
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).
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")
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"
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`.
Change the labels on the x- and y- axes to words instead of using the variable name. Make sure that the labels on both the x- and y-axes are capitalized.
Change the color of the bars to magenta.
The plot should have 15 bins.
There should be no background color, but you should retain the x- and y-axes.
# 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()
Create a histogram showing the distribution of the variable measuring the minutes someone is willing to drive for BBQ.
Change the labels on the x- and y-axes to words instead of using the variable name. Make sure that the labels on both the x- and y-axes are capitalized.
Change the color of the bars to violet.
The plot should have 25 bins.
There should be no background color but you should retain the x-and y-axes.
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.
Change the labels on the x- and y-axes to words instead of using the variable name. Make sure that the labels on both the x- and y-axes are capitalized.
Change the color of the line to lightblue4, and the color underneath the line to lightblue1.
The type of the line should be “twodash”.
There should be no background color but you should retain the x- and y-axes.
Add a vertical line at the mean of the variable.
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.
Change the labels on the x- and y- axes to words instead of using the variable name. Make sure that the labels on both the x- and y-axes are capitalized.
Change the color of the line to springgreen4, and the color underneath the line to springgreen1.
The type of the line should be “longdash”.
There should be no background color but you should retain the x and y axes.
Add a vertical line at the mean of the variable.
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()
Create a box-and-whisker plot of the variable measuring the price someone is willing to pay for a pulled pork sandwich.
The color of the box should be azure1 and the color of the outline of the box should be blue.
The color of the outliers should be darkcyan and the shape of the
outliers should be a *.
The orientation of this graph should be horizontal.
Make the appropriate adjustments to the labels, text, and tick marks for the x- and y-axis based on the orientation of the graph.
There should be no background color.
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")
)
Create a box-and-whisker plot of the variable measuring the minutes someone is willing to drive for BBQ.
The color of the box should be lightsteelblue1 and the color of the outline of the box should be lightsteelblue4.
The color of the outliers should be mediumpurple4 and the shape of the outliers should be an empty diamond.
The orientation of this graph should be vertical.
Make the appropriate adjustments to the labels, text, and tick marks for the x- and y- axis based on the orientation of the graph.
There should be no background color.
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")
)
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.
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
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.