- ggplot2 - Create Elegant Data Visualisations Using the Grammar of Graphics
ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details
- Introduction to ggplot2
ggplot2 is an R package for producing visualizations of data Unlike many graphics packages, ggplot2 uses a conceptual framework based on the grammar of graphics This allows you to ‘speak’ a graph from composable elements, instead of being limited to a predefined set of charts
- Package index • ggplot2
Package index Plot basics All ggplot2 plots begin with a call to ggplot(), supplying default data and aesthetic mappings, specified by aes() You then add layers, scales, coords and facets with + To save a plot to disk, use ggsave()
- Aesthetic specifications • ggplot2
Typically you specify font size using points (or pt for short), where 1 pt = 0 35mm In geom_text() and geom_label(), you can set size unit = "pt" to use points instead of millimeters In addition, ggplot2 provides a conversion factor as the variable pt, so if you want to draw 12pt text, you can also set size = 12 pt
- A box and whiskers plot (in the style of Tukey) — geom_boxplot • ggplot2
Thus, ggplot2 will by default try to guess which orientation the layer should have Under rare circumstances, the orientation is ambiguous and guessing may fail In that case the orientation can be specified directly using the orientation parameter, which can be either "x" or "y"
- Bar charts — geom_bar • ggplot2
Thus, ggplot2 will by default try to guess which orientation the layer should have Under rare circumstances, the orientation is ambiguous and guessing may fail In that case the orientation can be specified directly using the orientation parameter, which can be either "x" or "y"
- Complete themes — ggtheme • ggplot2
The classic dark-on-light ggplot2 theme May work better for presentations displayed with a projector theme_linedraw() A theme with only black lines of various widths on white backgrounds, reminiscent of a line drawing Serves a purpose similar to theme_bw() Note that this theme has some very thin lines (<< 1 pt) which some journals may refuse
- Layer position adjustments — layer_positions • ggplot2
In ggplot2, a plot is constructed by adding layers to it In addition to geoms and stats, position adjustments are the third required part of a layer The 'position' part of a layer is responsible for dodging, jittering and nudging groups of data to minimise their overlap, or otherwise tweaking their positions
|