Warning Don’t rely on current functionality for important scripts 8000 yet. It is very likely that ggplot2 changes their implementation of guides in the release after 3.4.0. At that point, the current functionality will cease to work.
The goal of gguidance is to provide additional guides to the ggplot2 ecosystem. Guides are re-implemented within the ggproto system to make use of the flexible extension framework.
Please note that this repo is still being worked on and, while probably usable, isn’t finished.
You can install the development version of gguidance from GitHub with:
# install.packages("devtools")
devtools::install_github("teunbrand/gguidance")
Here is a simple example of how to use an axis guide and a colour bar guide.
library(gguidance)
#> Loading required package: ggplot2
ggplot(msleep, aes(bodywt, sleep_total)) +
geom_point(aes(colour = sleep_rem)) +
scale_colour_viridis_c(guide = "colourbar_cap") +
scale_x_log10(guide = "axis_log")
#> Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
#> Please use the `linewidth` argument instead.
#> Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
#> Please use the `linewidth` argument instead.
Demonstrating a cross legend and axis subtitles.
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = paste(cyl, year))) +
guides(colour = "legend_cross",
x = guide_axis_ext(subtitle = "litres"),
y = guide_axis_ext(subtitle = "miles per gallon"))
So far, the following has been implemented:
- Axis guides
guide_axis_vanilla()
: A re-implementation ofguide_axis()
.guide_axis_ext()
: Extended options for axes.guide_axis_minor()
: Axes with minor ticks.guide_axis_trunc()
: Axes with truncated axis lines.guide_axis_log()
: Axes with log10-based tickmarks.guide_axis_table()
: Place a table at tickmarks.
- Legend guides
guide_legend_vanilla()
: A re-implementation ofguide_legend()
.guide_legend_cross()
: Combining two sets of labels in one legend.
- Colour bar guides
guide_colourbar_vanilla()
: A re-implementation ofguide_colourbar()
.guide_colourbar_cap()
: With cap decorations at the ends.
- Coordinate guides (a new feature in
coord_guided()
)guide_grid_vanilla()
: A re-implementation of default panel grids.guide_grid_zebra()
: Alternating stripes at/between breaks.guide_grid_swap()
: Displaying major grid as minor and minor grid as major. Convenient for separating places in discrete scales.
A medium-term goal is to move and refactor guides from the {ggh4x} package to {gguidance}. A longer-term goal is to make this package a hub for additional axes, legends and other guides.