If a question asks for any calculations (means, medians, tables, proportions, etc…) or graphs, make sure they appear in the knitted document
The final document should not show any warnings
See Brightspace for a description of the data. It’s the same data set as the homework for module 3 homework part 1.
Create and save a blank graph in ggplot named gg_limbs with arm length (humerus + tibia) on the x-axis and leg length (femur + tibia) on the y-axis. The non-data ink should match what is shown in Brightspace.
Note: Don’t create two new columns in the data set, create
the arm and leg variables inside ggplot()
gg_limbs <-
ggplot(
data = bones,
mapping = aes(
x = humerus + radius,
y = femur + tibia
)
) +
labs(
x = "Arm Length (mm)",
y = "Leg Length (mm)"
) +
theme_bw()
gg_limbs
You’ll be using this blank graph for most of the follow up parts for question 1.
Create a scatterplot using gg_limbs. Describe the 4 characteristics of the association between arm and leg lengths
gg_limbs +
geom_point()
Direction: Positive - As arm length increases, leg length also tends to increase
Outliers: There appears to be one noticeable outlier with an arm length of about 470 and a leg length around 800, which is a much longer leg length than what we’d expect for someone with their leg length
Trend: The relationship appears to be linear
Strength: The association is strong, most of the points are around the linear trend
What potential issue discussed in this module does the scatterplot from question 2 have? Recreate it with the appropriate solution to the issue
gg_limbs +
geom_point(alpha = 0.5)
Since there are over 1000 points on the graph, the problem is overplotting (too many points to clearly see the pattern).
Recreate the graph in part 1c but represent the age group using color. Is it easy to determine how the skeletons are different? Briefly explain your answer
gg_limbs +
geom_point(
mapping = aes(color = age),
alpha = 0.5
)
Update the graph from question 3 so each age has its own scatterplot. The axes for the 4 scatterplots should be the same
gg_limbs +
geom_point(
mapping = aes(color = age),
alpha = 0.5,
show.legend = F
) +
facet_wrap(facets = vars(age))
Does the association between arm and leg lengths differ based on age? Justify your answer using the graphs you created!
No, the relationship between arm length and leg length is about the same for all 4 age ranges.
Read in the “vg sales by year.csv” file and save it a vgames. Then plot the video game sales per year for Nintendo, Playstation, and Xbox on the same graph. Choose an appropriate theme, labels, and title.
Bonus: Color the Nintendo line red, Playstation line blue, and Xbox line green
# Read in the "vg sales by year.csv" file
vgames <- read.csv("vg sales by year.csv")
# Create the graph described in the question using vgames data set
ggplot(
data = vgames,
mapping = aes(
x = release_year,
y = sales,
color = platform
)
) +
geom_line(
linewidth = 1
) +
theme_bw() +
labs(
x = "Year",
y = "Sales (In Millions)",
title = "Video Game Sales per Year by Platform",
color = NULL
) +
scale_color_manual(
values = c("Nintendo" = "red",
"Playstation" = "blue",
"Xbox" = "green")
) +
# Add this to your graph to change the tick marks on the x-axis
scale_x_continuous(
breaks = seq(1996, 2018, 2),
minor_breaks = NULL
) +
# Add this to your graph to center title and move the legend inside the graph
theme(
legend.position = c(0.1, 0.85),
plot.title = element_text(hjust = 0.5)
)