data science: data visualization boot camp comparison bar ... · information graphics: a...
TRANSCRIPT
-
Data Science: Data Visualization Boot CampComparison
Bar Charts Across Time
Chuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhDChuck Cartledge, PhD
26 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 202026 January 2020
1/25
-
2/25
Type Sample data Hands on Q & A Conclusion References Files
Table of contents (1 of 1)
1 TypeUsesGeneral considerations
2 Sample data
3 Hands on
4 Q & A
5 Conclusion6 References7 Files
-
3/25
Type Sample data Hands on Q & A Conclusion References Files
A definition
“Grouped column graph (multiple data se-ries all referenced from the same zero axis) Whentwo or more data series are plotted side-by-sideon the same column graph, the result is referredto as a clustered, grouped, multiple, or side-by-side column graph. Grouped column graphs en-able the user to:
Compare multiple items at various pointsin timeShow how relationships between multipleitems change with timeLook for correlations or meaningfulrelationships between multiple data seriesCondense onto one graph what otherwisewould required multiple graphs
With this type of graph, each data element of
each data series is represented by a separate col-
umn.”
R. L. Harris [2]
-
4/25
Type Sample data Hands on Q & A Conclusion References Files
Federal Reserve Economic Data (1 of 2)
“The Federal Reserve Bank of St. Louis is
the center of the Eighth District of the Federal
Reserve System. . . . The Division monitors the
economic and financial literature and produces
research in the areas of money and banking,
macroeconomics, and international and regional
economics. . . . The Research Division also fur-
nishes its working papers to provide insight into
current Bank interests and developing theories
and to stimulate discussion. . . . The widely used
database FRED is updated regularly and allows
24/7 access to regional and national financial and
economic data.”
Fed. Res. Bank Staff [1]
-
5/25
Type Sample data Hands on Q & A Conclusion References Files
Federal Reserve Economic Data (2 of 2)
We select the data of interest. https://fred.stlouisfed.org
https://fred.stlouisfed.org
-
6/25
Type Sample data Hands on Q & A Conclusion References Files
Selecting data of interest
For manual, singular download: https:
//fred.stlouisfed.org/series/PCE
For programtic, singular download:
https:
//github.com/tidyverse/ggplot2/
blob/master/data-raw/economics.R
We elected to download a series programtically.
https://fred.stlouisfed.org/series/PCEhttps://fred.stlouisfed.org/series/PCEhttps://github.com/tidyverse/ggplot2/blob/master/data-raw/economics.Rhttps://github.com/tidyverse/ggplot2/blob/master/data-raw/economics.Rhttps://github.com/tidyverse/ggplot2/blob/master/data-raw/economics.R
-
7/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (1 of 6)
-
8/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (2 of 6)
rm(list=ls())
library(ggplot2)
saveFileName
-
9/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (3 of 6)
prettyNum(sum(df[,c("y1", "y2")]),
big.mark=",")),
title="Total imports for 2017",
y="Millions of dollars",
caption=paste0("Using data from:https://www.census.gov/",
"foreign-trade/data/index.html"),
fill="Countries"
) +
theme(plot.title=element_text(hjust = 0.5)) +
theme(plot.title=element_text(colour = "blue")) +
theme(plot.subtitle=element_text(hjust = 0.5)) +
theme(plot.subtitle=element_text(colour = "black")) +
theme(plot.caption=element_text(hjust = 0.0)) +
theme(plot.caption=element_text(colour = "red")) +
theme(legend.title.align=0.5) +
theme(axis.text.x=element_text(angle=0, hjust = 0)) +
theme(axis.text.x=element_blank()) +
theme(axis.ticks.x = element_blank())
-
10/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (4 of 6)
g + geom_rect(alpha=0.5, color="black")
df
-
11/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (5 of 6)
"foreign-trade/data/index.html"),
fill="Countries"
) +
theme(plot.title=element_text(hjust = 0.5)) +
theme(plot.title=element_text(colour = "blue")) +
theme(plot.subtitle=element_text(hjust = 0.5)) +
theme(plot.subtitle=element_text(colour = "black")) +
theme(plot.caption=element_text(hjust = 0.0)) +
theme(plot.caption=element_text(colour = "red")) +
theme(legend.title.align=0.5) +
theme(axis.text.x=element_text(angle=0, hjust = 0)) +
theme(axis.text.x=element_blank()) +
theme(axis.ticks.x = element_blank())
g + geom_rect(alpha=0.5, color="black") +
geom_hline(yintercept=0)
-
12/25
Type Sample data Hands on Q & A Conclusion References Files
The first codes. (6 of 6)
-
13/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (1 of 8)
-
14/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (2 of 8)
rm(list=ls())
library(ggplot2)
saveFileName
-
15/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (3 of 8)
df$y1
-
16/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (4 of 8)
caption=paste0("Using data from:https://www.census.gov/",
"foreign-trade/data/index.html"),
fill="Countries"
) +
theme(plot.title=element_text(hjust = 0.5)) +
theme(plot.title=element_text(colour = "blue")) +
theme(plot.subtitle=element_text(hjust = 0.5)) +
theme(plot.subtitle=element_text(colour = "black")) +
theme(plot.caption=element_text(hjust = 0.0)) +
theme(plot.caption=element_text(colour = "red")) +
theme(legend.title.align=0.5) +
theme(axis.text.x=element_text(angle=0, hjust = 0)) +
theme(axis.text.x=element_blank()) +
theme(axis.ticks.x = element_blank())
g + geom_rect(data=df, aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2),
fill="red", alpha=0.5,
color="black", inherit.aes=FALSE) +
-
17/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (5 of 8)
geom_rect(data=df, aes(xmin=x2, xmax=x3, ymin=y1, ymax=y3),
fill="green", alpha=0.5,
color="black", inherit.aes=FALSE) +
geom_rect(data=df, aes(xmin=x3, xmax=x4, ymin=y1, ymax=y4),
fill="blue", alpha=0.5,
color="black", inherit.aes=FALSE) +
geom_rect(data=df, aes(xmin=x4, xmax=x5, ymin=y1, ymax=y5),
fill="yellow",alpha=0.5, color="black",
inherit.aes=FALSE) +
geom_text(aes(x=1:length(countriesOfInterest),
y=c(rep(max(df[,7:11]), length(countriesOfInterest)))
),
label=df$country,
color="blue",
angle=0,
nudge_x=0.0,
nudge_y=0.0,
inherit.aes=FALSE
-
18/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (6 of 8)
)
newOrder
-
19/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (7 of 8)
) +
theme(plot.title=element_text(hjust = 0.5)) +
theme(plot.title=element_text(colour = "blue")) +
theme(plot.subtitle=element_text(hjust = 0.5)) +
theme(plot.subtitle=element_text(colour = "black")) +
theme(plot.caption=element_text(hjust = 0.0)) +
theme(plot.caption=element_text(colour = "red")) +
theme(legend.title.align=0.5) +
theme(axis.text.x=element_text(angle=0, hjust = 0)) +
theme(axis.text.x=element_blank()) +
theme(axis.ticks.x = element_blank())
g + geom_rect( aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2), fill="red",
alpha=0.5, color="black", inherit.aes=FALSE) +
geom_rect( aes(xmin=x2, xmax=x3, ymin=y1, ymax=y3), fill="green",
alpha=0.5, color="black", inherit.aes=FALSE) +
geom_rect( aes(xmin=x3, xmax=x4, ymin=y1, ymax=y4), fill="blue",
alpha=0.5, color="black", inherit.aes=FALSE) +
-
20/25
Type Sample data Hands on Q & A Conclusion References Files
The second codes. (8 of 8)
geom_rect( aes(xmin=x4, xmax=x5, ymin=y1, ymax=y5), fill="yellow",
alpha=0.5, color="black", inherit.aes=FALSE) +
geom_text(aes(x=1:length(countriesOfInterest),
y=c(rep(max(df[,7:11]), length(countriesOfInterest)))
),
label=df$country,
color="blue",
angle=0,
nudge_x=0.0,
nudge_y=0.0,
inherit.aes=FALSE
)
-
21/25
Type Sample data Hands on Q & A Conclusion References Files
Hands-on exercises
1 In the first set of slides, your supervisor wants number ofchanges:
1 The last slide shows the magnitude of our country’s import andexport with various countries. Change the data to show thebalance of trade, vice the magnitude of the import and export.
2 In the second set of slides:1 Your supervisor wants the country names to not collide with
the plotted data.2 Change the countries to be: China, Hong Kong, Japan, South
Korea, Singapore, and Taiwan.
-
22/25
Type Sample data Hands on Q & A Conclusion References Files
Q & A time.
Q: How many Oregonians does ittake to screw in a light bulb?A: Three. One to screw in thelight bulb and two to fend off allthose Californians trying to sharethe experience.
-
23/25
Type Sample data Hands on Q & A Conclusion References Files
What have we covered?
Bar charts with few items are:
Useful to show the relative sizesof different components acrossdifferent categories.Can be easily overwhelmed ifthere are too many categories.
Good for showing componentrelationships across categories.
Next: Comparing a many categories across a few periods.
-
24/25
Type Sample data Hands on Q & A Conclusion References Files
References (1 of 1)
[1] Fed. Res. Bank Staff,About Economic Research at the St. Louis Fed,https://research.stlouisfed.org/about.html, 2018.
[2] Robert L. Harris,Information Graphics: A Comprehensive Illustrated Reference,Oxford University Press, 2000.
https://research.stlouisfed.org/about.html
-
25/25
Type Sample data Hands on Q & A Conclusion References Files
Files of interest
1 Code snippet to createimages in this presentation
2 Extract Federal Export and
Import data
## First codesrm(list=ls())
library(ggplot2)
saveFileName