Presentation Slides

CREATING POWERFUL
AND EFFECTIVE
GRAPHICAL DISPLAYS
An Introduction to Lattice Graphics in R
William G. Jacoby
Michigan State University
[email protected]
http://polisci.msu.edu/jacoby/apsa07/graphics/
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 1: A unidimensional scatterplot.
0
20
40
60
State policy priorities, 1992
80
100
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 2: A histogram.
Percent of Total
30
20
10
0
0
20
40
60
State policy priorities, 1992
80
100
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 3: A smoothed histogram.
0.020
Density
0.015
0.010
0.005
0.000
0
50
State policy priorities, 1992
100
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 4: A dot plot.
.
WY
ID
MT
NV
UT
ND
DE
KS
NM
WV
VT
IA
SD
NC
CO
OK
WA
AR
VA
AZ
KY
MS
NE
IN
FL
OR
TX
MN
MO
AL
WI
SC
GA
OH
LA
NJ
MD
IL
ME
TN
CA
RI
MI
PA
CT
NY
NH
MA
0
20
40
60
80
State policy priorities, 1992
100
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 5: Dot plot, with different line style.
WY
ID
MT
NV
UT
ND
DE
KS
NM
WV
VT
IA
SD
NC
CO
OK
WA
AR
VA
AZ
KY
MS
NE
IN
FL
OR
TX
MN
MO
AL
WI
SC
GA
OH
LA
NJ
MD
IL
ME
TN
CA
RI
MI
PA
CT
NY
NH
MA
0
20
40
60
80
State policy priorities, 1992
100
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 6: A scatterplot.
100
State policy priorities, 1992
80
60
40
20
0
-0.3
-0.2
-0.1
0.0
Ideology of state electorate, 1992
0.1
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 7: A quantile comparison plot.
State electorate partisanship
0.2
0.0
-0.2
-0.4
-0.4
-0.2
0.0
State electorate ideology
0.2
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 8: Histogram, with text tick labels on horizontal axis.
Percent of Total
30
20
10
0
Par. Bens.
Mixed
State policy priorities, 1992
Coll. Gds.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 9: Histogram, with two-line text tick labels on horizontal axis.
Percent of Total
30
20
10
0
Particularized
Benefits
Mixed
Priorities
State policy priorities, 1992
Collective
Goods
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 10: Scatterplot with a third variable encoded into the plotting symbols.
100
State policy priorities, 1992
80
60
40
20
0
100
200
300
400
Strength of interest groups in state
500
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 11: Scatterplot with coded plotting symbols and a key.
Republican electorates
Democratic electorates
100
State policy priorities, 1992
80
60
40
20
0
100
200
300
400
Strength of interest groups in state
500
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 12: Scatterplot with a loess curve fitted to the data.
100
State policy priorities, 1992
80
60
40
20
0
100
200
300
400
Strength of interest groups in state
500
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 13: Scatterplot with loess curve and OLS line fitted to the data.
Loess curve
OLS line
100
State policy priorities, 1992
80
60
40
20
0
100
200
300
400
Strength of interest groups in state
500
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 14: A multipanel trellis display showing policy priorities, by region.
0
20
south
40
60
80
100
west
40
30
Percent of Total
20
10
0
midwest
northeast
40
30
20
10
0
0
20
40
60
80
100
State policy priorities, 1992
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 15: Obtaining R.
A. The R-Project Web Site.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 15: Obtaining R.
B. Selecting a CRAN Mirror for the download.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 15: Obtaining R.
C. The download page.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 15: Obtaining R.
D. After downloading, double-click on the icon for the executable file.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 16: Installing packages in R
A. Within R, click on “Packages” and “Install package(s) ...”.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 16: Installing packages in R
B. Select a CRAN mirror from which to download packages.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 16: Installing packages in R
C. Select a package to download.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 17: Use the “library()” function to load the lattice package.
William G. Jacoby
Creating Powerful and Effective Graphical Displays
Figure 18: Lattice graphs are rendered within a separate window.