knitr::opts_chunk$set(echo = T,
warning = F,
message = F,
fig.align = "center",
fig.height = 8,
fig.width = 8)
## Load the required package: tidyverse
library(tidyverse)
## Read in the coasters.csv file as coasters
coasters <- read.csv('coasters.csv')
The coasters data set has the information on 766 roller coasters. There are twelve variables (columns), and the relevant ones are:
name: Name of the roller coastertype: The type of roller coaster
(wood/steel/other)lift: The way the coaster is lifted up the first hill
(chain/launch/other)length_ft & height_ft: The length and
height of the roller coaster, in feetspeed_mph: The max speed of the coaster, in miles per
hourCreate a scatterplot of the speed_mph by
height_ft with the points colored by
length_ft, shaped by lift, and partially
transparent. See what the graph should look like in Brightspace.
Save the graph as gg_q1 and display the graph in the
knitted document.
gg_q1 <-
ggplot(
data = coasters,
mapping = aes(
x = height_ft,
y = speed_mph
)
) +
geom_point(
mapping = aes(
color = length_ft,
shape = lift
),
alpha = 0.75
)
gg_q1
Does something seem wrong with the data? Describe what stands out as likely incorrect
Create the graph seen in question 2 in Brightspace. Save the graph as
gg_q2 and display it in the knitted document.
gg_q2 <-
gg_q1 +
# Adding the title, caption, and changing the label
labs(
title = "Roller Coasters: Speed, Height, and Length",
x = "Height",
y = "Speed",
color = 'Length',
shape = 'Lift Type',
caption = 'Data: rcdb.com'
) +
# Changing the theme
theme_test() +
# Custom theme changes
theme(
# Centering the title
plot.title = element_text(hjust = 0.5, size = 16),
# Moving the legend to the bottom
legend.position = 'bottom'
) +
# Leave this at the bottom to get the gradient bar to match
guides(color = guide_colorbar(barwidth = 15, barheight = 1))
gg_q2
Using the graph created in question 2, create the graph seen in Brightspace for question three. Make sure to pay close attention to the labels used for all 4 aesthetics!
Hint: You can use the help menu for the approbriate function to find how to get the colors to match!
Save the graph as gg_q3 and make sure to display it in
the knitted document!
gg_q3 <-
gg_q2 +
# Adding units to the axes
scale_x_continuous(
breaks = 0:9*50,
labels = paste0(0:9*50, 'ft')
) +
scale_y_continuous(
breaks = 0:6*25,
labels = paste0(0:6*25, 'mph')
) +
# Changing the color and labels
scale_color_continuous(
type = 'viridis',
breaks = (1:4)*2000,
labels = c('2000ft','4000ft', '6000ft', '8000ft')
) +
# Capitalizing Chain, Launch, and Other for lift
scale_shape_manual(
values = c('chain' = 'circle',
'launch' = 'triangle',
'other' = 'asterisk'),
labels = c('chain' = 'Chain',
'launch' = 'Launch',
'other' = 'Other')
)
gg_q3
Using gg_q3, create three small multiples, one for Wood,
one for Steel, and one for Other.
Since this is the final question, you don’t need to save the graph
gg_q3 +
facet_wrap(
facets = vars(type),
ncol = 1
)
Which type of coaster is the most common?
Which type of coaster is the rarest?