03:00
ggplot()
IntroSeptember 18, 2024
ggplot()
{patchwork}
Single Numerical Variable
Single Categorical Variable
Two Numerical Variables
Two Categorical Variables
One Numerical and One Categorical Variable
Day2to5_AustinHousingData.qmd
file that we’ve been working withinVisualizing the Austin Zillow Data
subsection03:00
ggplot()
Note we can pipe (%>%
) a data frame into a plot
Once we use ggplot()
we use +
to add layers instead of piping
geom_*()
layers require aesthetics to map variables to plot features
Can add multiple geoms to a single plot
Every plot should include labels
Single Numerical Variable
geom_boxplot()
, geom_histogram()
, or geom_density()
x
or y
aesthetic (but not both!)geom_density(aes(x = hwy))
Single Categorical Variable
geom_bar()
x
or y
aesthetic (but not both!)geom_bar(aes(x = class))
geom_col()
x
and y
aestheticgeom_col(aes(x = class, y = n))
Two Numerical Variables
geom_point()
or geom_hexbin()
x
and y
aestheticgeom_point(aes(x = cty, y = hwy))
Two Categorical Variables
geom_bar()
x
and fill
aestheticsgeom_bar(aes(x = class, fill = drv))
One Numerical and One Categorical Variable
geom_boxplot()
x
and y
aestheticsgeom_boxplot(aes(x = hwy, y = class))
geom_density()
or geom_histogram()
x
aestheticfacet_wrap(~ VAR_NAME)
Other available aesthetics include color
, size
, shape
, and alpha
(transparency)
\(\bigstar\) Build plot(s) to help answer give us insight into the distribution of the lot size variable. If you’re successful (or if you just want to try something else), move on to plots that show the distribution of city or price range, or even to try building a plot to examine a potential association between number of bedrooms and price range. Take five minutes and then we’ll debrief together.
05:00
\(\bigstar\) Use your knowledge of data visualization and ggplot
to build basic plots to answer at least two of the questions you wrote out earlier. If you write broken code, troubleshoot with a neighbor, pull me over, or even post to Slack for help. See what you can do in 7 minutes and then debrief together for an additional three.
# r-questions
channel in Slack!
07:00
\(\bigstar\) Use your knowledge of data visualization and ggplot
to build basic plots to answer at least two of the questions you wrote out earlier. If you write broken code, troubleshoot with a neighbor, pull me over, or even post to Slack for help. We’ll see what we can do in 7 minutes and then debrief together for an additional three.
Made a plot you are proud of? Post it and the code to the # r-questions
channel in Slack!
03:00
The labs()
layer permits global plot labels and labels for any mapped aesthetic
title
subtitle
caption
alt
(for alt-text)x
y
color
fill
\(\bigstar\) Now that you know about labeling options in the labs()
layer, update your plots with meaningful labels
05:00
{patchwork}
{patchwork}
package provides very easy and intuitive framework for doing this.Create each of your plots, but store them into variables p1
, p2
, …
Use +
to organize plots side-by-side, and /
to organize plots over/under one another.
(p1 + p2) / p3
will arrange plots p1
and p2
side-by-side, with plot p3
underneath them.
\(\bigstar\) Use {patchwork}
to experiment with different arrangements of your plots
05:00
Ask at several more questions that can be answered using data visualization
Construct relevant visuals (including meaningful labels) to answer your questions
{patchwork}
if you like{patchwork}
is used versus when it is notProvide interpretations of the plots you are seeing
A Transition Into Probability