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/rlmcollins/Desktop"
setwd("/Users/rlmcollins/Desktop")

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")
VisualizingVariablesData <- read.xlsx("BBQData_Assignment8.xlsx")
names(VisualizingVariablesData)
##  [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(VisualizingVariablesData,      #data argument
       aes(x=Ribs.Price)) +   #mapping and aesthetics arguments
  geom_histogram()                    #geom argument
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Ribs.Price)) + geom_histogram()   +     
    labs(x="Ribs Price",  y="Count") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Ribs.Price)) + geom_histogram(fill="magenta")   +     
    labs(x="Ribs Price",  y="Count") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Ribs.Price)) +  geom_histogram(fill="magenta", bins = 15)   +    
    labs(x="Ribs Price", y="Count") 

ggplot(VisualizingVariablesData,     
       aes(x=Ribs.Price)) +   
  geom_histogram(fill="magenta", bins = 15)   +      
    labs(x="Ribs Price",           
       y="Count")  +
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line())     

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(VisualizingVariablesData,      #data argument
       aes(x=Minutes.Driving)) +   #mapping and aesthetics arguments
  geom_histogram()                    #geom argument
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + geom_histogram()   +     
    labs(x="Minutes Driving",  y="Count")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + geom_histogram(fill="violet")   +     
    labs(x="Minutes Driving",  y="Count") 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) +  geom_histogram(fill="violet", bins = 25)   +    
    labs(x="Minutes Driving", y="Count")

ggplot(VisualizingVariablesData,     
       aes(x=Minutes.Driving)) +   
  geom_histogram(fill="violet", bins = 25)   +      
    labs(x="Minutes Driving",           
       y="Count")  +
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line())  

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(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density()

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density() +
 labs(x="Minutes Driving",  y="Density") 

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density(color="lightblue4", fill="lightblue1") +
 labs(x="Minutes Driving",  y="Density")

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density(color="lightblue4", fill="lightblue1", linetype="twodash") +
 labs(x="Minutes Driving",  y="Density") 

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density(color="lightblue4", fill="lightblue1", linetype="twodash") +
 labs(x="Minutes Driving",  y="Density") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line())    

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_density(color="lightblue4", fill="lightblue1", linetype="twodash") +
 labs(x="Minutes Driving",  y="Density") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line())  +
  geom_vline(aes(xintercept=mean(Minutes.Driving)))

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(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density()

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density() +
 labs(x="Sandwhich Price",  y="Density")

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density(color="springgreen4", fill="springgreen1") +
 labs(x="Sandwich Price",  y="Density")

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density(color="springgreen4", fill="springgreen1", linetype="longdash") +
 labs(x="Sandwich Price",  y="Density")

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density(color="springgreen4", fill="springgreen1", linetype="longdash") +
 labs(x="Sandwich Price",  y="Density") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line()) 

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_density(color="springgreen4", fill="springgreen1", linetype="longdash") +
 labs(x="Sandwich Price",  y="Density") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line())  +
  geom_vline(aes(xintercept=mean(Sandwich.Price)))

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(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot()

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot(fill = "azure1", colour = "blue")

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot(fill = "azure1", colour = "blue", outlier.colour = "darkcyan", outlier.shape = 8)

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot(fill = "azure1", colour = "blue", outlier.colour = "darkcyan", outlier.shape = 8) + 
  labs(x="Sandwich Price",  y="") + 
  coord_flip()

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot(fill = "azure1", colour = "blue", outlier.colour = "darkcyan", outlier.shape = 8) + 
  labs(x="Sandwich Price",  y="") + 
  theme(axis.line = element_line(),axis.text.x = element_blank(),axis.ticks.x = element_blank()) +
  coord_flip()

ggplot(VisualizingVariablesData, aes(x=Sandwich.Price)) + 
  geom_boxplot(fill = "azure1", colour = "blue", outlier.colour = "darkcyan", outlier.shape = 8) + 
  labs(x="Sandwich Price",  y="") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank()) +
  coord_flip()

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(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot()

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot(fill = "lightsteelblue1", colour = "lightsteelblue4")

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot(fill = "lightsteelblue1", colour = "lightsteelblue4", outlier.colour = "mediumpurple4", outlier.shape = 5)

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot(fill = "lightsteelblue1", colour = "lightsteelblue4", outlier.colour = "mediumpurple4", outlier.shape = 5)

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot(fill = "lightsteelblue1", colour = "lightsteelblue4", outlier.colour = "mediumpurple4", outlier.shape = 5) + 
  labs(x="Minutes Driving",  y="") + 
  theme(axis.line = element_line(),axis.text.y = element_blank(),axis.ticks.y = element_blank())

ggplot(VisualizingVariablesData, aes(x=Minutes.Driving)) + 
  geom_boxplot(fill = "lightsteelblue1", colour = "lightsteelblue4", outlier.colour = "mediumpurple4", outlier.shape = 5) + 
  labs(x="Minutes Driving",  y="") + 
  theme(panel.grid.major = element_blank(),     
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), 
        axis.line = element_line(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank()) 

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

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 did not 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.