ggplot2The objective of this assignment is to complete and explain basic plots before moving on to more complicated ways to graph data.
Each question is worth 5 points.
To submit this homework you will create the document in Rstudio,
using the knitr package (button included in Rstudio) and then submit the
document to your Rpubs account. Once
uploaded you will submit the link to that document on Canvas. Please
make sure that this link is hyperlinked and that I can see the
visualization and the code required to create it
(echo=TRUE).
mosaicData package.To identify each of the visual cues, I have used: Cartesian
coordinate system with a clear context, which consists of the title and
x & y axis labels.
- Create a data
graphic with at least five variables (either quantitative or
categorical). For the purposes of this exercise, do not worry about
making your visualization meaningful—just try to encode five variables
into one plot.
ggplot(data = Marriage, aes(x=age, y=college, color = person, shape = race, size = hs)) +
geom_point() +
theme_bw() +
labs(x = "Age", y = "Years in College",
title = "The Relationship between Marriage Age and Years in College by Offical Title, Race and Years in High School")
## Warning: Removed 10 rows containing missing values (geom_point).
Your objective for the next four questions will be write the code necessary to exactly recreate the provided graphics.
This boxplot was built using the mpg dataset. Notice the
changes in axis labels.
This graphic is built with the diamonds dataset in the
ggplot2 package.
This graphic uses the penguins dataset and shows the
counts between males and females by species.
ggplot(penguins, aes(x = sex, fill = species)) +
theme_bw() +
geom_bar(alpha = 0.8) +
scale_fill_brewer(palette = 'Dark2') +
theme_minimal() +
facet_wrap(~species, ncol = 1) +
coord_flip() +
labs(x ="Sex", y = "Count")
This figure examines the relationship between bill length and depth
in the penguins dataset.
ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
geom_point() +
geom_smooth(method = "lm", aes(color = species)) +
labs(
col = 'Species',
title = 'Scatterplot Between Bill Length and Depth By Species',
x = 'Bill Length (mm)',
y = 'Bill Depth (mm)',
)