R: What are the pros and cons of using Lattice versus ggplot2?
Which of this is limitation of lattice plots?
Sometimes awkward to specify an entire plot in a single function call. Annotation in plot is not intuitive. Use of panel functions and subscripts difficult to wield and requires intense preparation. Cannot “add” to the plot once it's created.
What does Lattice do in R?
The lattice add-on package is an implementation of Trellis graphics for R. It is a powerful and elegant high-level data visualization system with an emphasis on multivariate data.
What is the difference between Ggplot and plot?
The base plotting paradigm is "ink on paper" whereas the lattice and ggplot paradigms are basically writing a program that uses the grid -package to accomplish the low-level output to the target graphics devices.
Love what Roger Peng said when comparing Base/Lattice/gglot2 packages in his ppt: https://github.com/rdpeng/CourseraLectures/blob/master/ggplot2_part1.pptx
Base
- “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)
Pros:
Convenient, mirrors how we think of building plots and analyzing data
Cons:
- 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
Lattice
Plots are created with a single function call (xyplot, bwplot, etc.)
Pros:
- Most useful for conditioning types of plots: Looking at how y changes with x across levels of z
- Thinks like margins/spacing set automatically because entire plot is specified at once
- Good for putting many many plots on a screen
Cons:
- Sometimes awkward to specify an entire plot in a single function call
- Annotation in plot is not intuitive
- Use of panel functions and subscripts difficult to wield and requires intense preparation
- Cannot “add” to the plot once it’s created
ggplot2
Pros:
- Split the difference between base and lattice
- Automatically deals with spacing, text, titles but also allows you to annotate by “adding”
- Superficial similarity to lattice but generally easier/more intuitive to use
- Default mode makes many choices for you (but you can customize!)