0. Use the following code to download the King County restaurants
data:
load(url("https://pearce790.github.io/CSSS508/Lectures/Lecture8/restaurants.Rdata"))
1. Strings
Question 1.1: Use a function to determine how long the following
character string is: paste0(letters,1:5,collapse=":")
# YOUR CODE HERE
Question 1.2: Describe, in 1-2 complete sentences, the difference
between the arguments “sep” and “collapse” in the paste()
function.
ANSWER:
Question 1.3: Filter your data to only include rows in which the
Name includes the word “coffee” (in any case!)
# YOUR CODE HERE
Question 1.4: Create a new variable in your data which includes the
length of the business name, after removing beginning/trailing
whitespace.
# YOUR CODE HERE
Question 1.5: Create a new variable in your data for the inspection
year, using a stringr function!
# YOUR CODE HERE
Question 1.6: Create side-by-side boxplots for the length of
business name vs. year.
# YOUR CODE HERE
Question 1.7: Calculate the maximum Inspection_Score by
business (Name) and Year.
# YOUR CODE HERE
Question 1.8: Create a line plot of maximum score (“MaxScore”) over
time (“Year”), by business (“Name”). That is, you should have a single
line for each business. (Don’t try to label them, as there are far too
many!)
# YOUR CODE HERE
2. Mapping
Question 2.1: Using your data from part 1, create a ggplot
displaying each coffee shop in King County by their latitude/longitude.
For this question, no need to display any actual map data!
# YOUR CODE HERE
Question 2.2: Modify the City variable so that it is in
title case. Then, modify your plot from 2.1 such that each city has a
different color.
# YOUR CODE HERE
Question 2.3: Recreate the plot from 2.2 using the
qmplot function in the gmap package
# YOUR CODE HERE
Question 2.4: Create a density plot of coffee shops in Bellevue
Filter to coffee shops in Bellevue first!!
# YOUR CODE HERE
Question 2.5: Create a new dataset called that includes the name,
latitude, and longitude of each Starbucks coffee store in Bellevue.
Remove any duplicates by year.
Hint: Use the select, filter, and
distinct functions (in that order). Within
filter, you’ll use str_detect.
# YOUR CODE HERE
Question 2.6: Plot all Bellevue coffee shops, then add labels for
the Starbucks stores using geom_label_repel
# YOUR CODE HERE