The document discusses different plotting systems in R, including the Base Plotting System, Lattice Plot, and ggplot2. It highlights the strengths and weaknesses of each system, such as the Base system's 'artist's palette' model and the ease of use in ggplot2. The document emphasizes the importance of planning in advance when using these plotting systems due to their varying levels of flexibility and customization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views11 pages
PlottingSystems For R
The document discusses different plotting systems in R, including the Base Plotting System, Lattice Plot, and ggplot2. It highlights the strengths and weaknesses of each system, such as the Base system's 'artist's palette' model and the ease of use in ggplot2. The document emphasizes the importance of planning in advance when using these plotting systems due to their varying levels of flexibility and customization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Plotting Systems in R
Roger D. Peng, Associate Professor of Biostatistics
Johns Hopkins Bloomberg School of Public HealthThe Base Plotting System
~ "Artist's palette" model
+ Start with blank canvas and build up from there
Start with plot function (or similar)
Use annotation functions to add/modify (text, Lines, points, axis)+ Convenient, mirrors how we think of building plots and analyzing data
Can't go back once plot has started (i.e. to adjust margins); need to plan in advance
Difficult to "translate" to others once a new plot has been created (no graphical "language"
+ Plot is just a series of R commands
antBase Plot
Library (datasets)
data(cars)
with(cars, plot(speed, dist))
aia
2 4 80 100 1
°Plots are created with a single function call (xyplot, bwplot, etc.)
Most useful for conditioning types of plots: Looking at how y changes with x across levels of z
Things like margins/spacing set automatically because entire plot is specified at once
+ Good for puttng many many plots on a screen
sit+ Sometimes awkward to specify an entire plot in a single function call
Annotation in plot is not especially intuitive
Use of panel functions and subscripts difficult to wield and requires intense preparation
~ Cannot "add" to the plot once it is created
entLattice Plot
Library(lattice)
state < [Link](state.x77, region = [Link])
xyplot ([Link] ~ Income | region, data = state, layout = (4, 1))
Bn ca .
74+ Splits the difference between base and lattice in a number of ways
Automatically deals with spacings, text, titles but also allows you to annotate by "adding" to a plot
Superficial similarity to lattice but generally easier/more intuitive to use
+ Default mode makes many choices for you (but you can stil customize to your heart's desire)
entggplot2 Plot
Library (ggplot2)
data(mps)
qplot(displ, hwy, data = mpg)
“asoSummary
+ Base: “artist's palette" model
Lattice: Entire plot specified by one function; conditioning
ggplot2: Mixes elements of Base and Lattice
4071References
Paul Murrell (2011). R Graphics, CRC Press.
Hadley Wickham (2009). ggplot2, Springer.
an