R: What are the pros and cons of using Lattice versus ggplot2?
R: What are the pros and cons of using Lattice versus ggplot2? [closed]
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!)
Cons of ggplot2: (1) "magic" evaluation model (i.e., very different from base R and other packages, perhaps harder to understand); (2) probably even harder to customize (beyond what the package allows) than lattice; (3) as answered below, no 3-D perspective plots corresponding to persp() [base], wireframe()/cloud() [lattice]; (4) lattice contains some functionality, like banking (aspect ratio control), that is not in ggplot; (5) speed; ggplot is slow compared to lattice, especially for faceting. –
Horseback
This is summarized very nicely in a set of blog posts on the Learn R blog.
ggplot2 currently does not support true 3d surfaces, according to this post:
ggplot2 Version of Figures in “Lattice: Multivariate Data Visualization with R”
© 2022 - 2024 — McMap. All rights reserved.