Outliers in Rust Belt/Economically Depressed Areas
Sensitivity to years chosen
HW 1 Review
More thought into what data is being used
Articles specific that permits lead rents
Choice of years for everything matters
Scatterplots
Shows how two variables are associated
Scatterplots
Shows how two variables are associated
library(tidyverse)library(palmerpenguins)library(ggplot2)penguins |>ggplot(aes(x=body_mass_g,y=flipper_length_mm)) +geom_point() +theme_bw(base_size =18) +theme(aspect.ratio=0.67) +labs( title ="Flipper Length Increases With Body Mass") +xlab("Body Mass (g)") +ylab("Flipper Length (mm)")
Multiple Types of Penguins
Can add categorical information several ways:
Color/Shape (Same Graph)
Facets (Different Graphs)
Multiple Types of Penguins
Can add categorical information several ways:
Color/Shape (Same Graph)
Facets (Different Graphs)
Redundant Coding
Some people can differentiate better when the additional variable is coded multiple times
Limits on Channels
Using multiple “channels” for different variables overloads the brain
Practical limit is 1 categorical variable redundantly coded
Facets
Facet Grid and Facet wrap allow more annotations
When to use Facets?
Showing on the same plot is better because of direct comparisons unless:
You want to show several categories
Too many elements in category (6?)
Facilitating Comparisons with Facets
Show all points on each facet
Facilitating Comparisons with Facets
penguins |>filter(sex %in%c("male","female")) |>ggplot(aes(x=body_mass_g,y=flipper_length_mm,color=species,shape = species, fill = species)) +geom_point(data =transform(penguins, sex =NULL, island =NULL), color ="grey90",fill="grey90") +facet_grid(sex ~ island) + ... other
Add to old plot another geom_point
NULL the facet categories
Force a light color
Scatterplot Annotations
Reduce cognitive load by labeling directly
stat_ellipse draws ellipses around groups
Scatterplot Annotations
penguins |>ggplot(aes(x=body_mass_g,y=flipper_length_mm,color=species,shape = species, fill = species)) +geom_point() +stat_ellipse(size=0.5) +other_commands(...)
When the number of variables is high, false discovery rate
Can be challenging to look at
Later in semester we will discuss dimensional reduction
Time Series
Time series are like a scatterplot
Time variable gives additional structure
Commonly use line plots instead of points
Time Series
Time series are like a scatterplot
Time variable gives additional structure
Commonly use line plots instead of points
Time Series
Time series are like a scatterplot
Time variable gives additional structure
Commonly use line plots instead of points
library(TTR)gdp =read_csv("GDPC1.csv")gdp = gdp |>mutate(growth =100*(GDPC1/lag(GDPC1,4)-1)) gdp |>ggplot(aes(x=observation_date,y=growth)) +geom_line(color="blue") +theme_bw(base_size=16) +theme(panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank() )+labs(title="Real GDP Growth Rate") +xlab("Date") +ylab("TTM Real GDP Growth Rate (%)")
Multiple Time Series
Unless units are the same, use multiple plots
I like to use the patchwork package
Multiple Time Series
Unless units are the same, use multiple plots
I like to use the patchwork package
library(patchwork)unemp =read_csv("UNRATE.csv")p1 = gdp |>ggplot(aes(x=observation_date,y=growth)) +geom_line(color="blue") +theme_clean(base_size=16) +theme(panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),plot.background =element_rect(color =NA) ) +labs(title ="Unemployment and GDP Growth")+xlab("") +ylab("TTM Real GDP Growth (%)")p2 = unemp |>ggplot(aes(x=observation_date,y=UNRATE)) +geom_line(color="blue") +theme_clean(base_size=16) +theme(panel.grid.minor.x =element_blank(),panel.grid.major.x =element_blank(),plot.background =element_rect(color =NA) )+ylab("Unemployment Rate (%)")+xlab("")p1/p2