Ggplot2: A Layer-Based Introduction NYC R Meetup October 1st, 2009 Harlan D. Harris Harlan@harris - Name December 3rd
Ggplot2: A Layer-Based Introduction NYC R Meetup October 1st, 2009 Harlan D. Harris Harlan@harris - Name December 3rd
a layer-based introduction
NYC R Meetup
December
October 3rd,
1st, 2009
Harlan D. Harris
[email protected]
ggplot's philosophy
● Graphics are (should be!) created by combining
a specification with data. (Wilkinson, 2005)
● The specification is not the name of the visual
form (bar graph, scatterplot, histogram).
● The specification is a collection of rules that
together describe how to build a graph, a
Grammar of Graphics
data
10
12 8 Column
10 1
6
8 Colum Column
2
6
4
n1
Colum date ct sz z 4
2
Column
n2 3
2 Colum 0
0 n3
Row 2 Row 4
Row 2 Row 4 Row 1 Row 3
Row 1 Row 3
x=date
y=ct/sz
me bars
group by z
ggplot
data layers mapping scales coords facets options
x=Param.
(copy) Ø y=Errs
color=Cond.
layer[1]
data mapping geom stat geom_ stat_
identity params params
line
● structure(p), str(p)
December 3, 2009 Harlan D. Harris 12
add empirical data and chance
layer[1]
data mapping geom stat geom_ stat_
layer[1] line identity params params
data mapping geom stat geom_ stat_
layer[1] params params
(U)
data mapping
point
geom
identity
stat
size=3
geom_ stat_
layer[1] params params
(K)
data yint=Errs
mapping hline
geom hline
stat size=2
geom_ stat_
color=”black”
params params
linetype=2
yint=[64] hline hline size=.5