Language: | en-GB |
Title: | Multiple Fill and Colour Scales in 'ggplot2' |
Version: | 0.5.2 |
Description: | Use multiple fill and colour scales in 'ggplot2'. |
License: | GPL-3 |
URL: | https://eliocamp.github.io/ggnewscale/, https://github.com/eliocamp/ggnewscale |
BugReports: | https://github.com/eliocamp/ggnewscale/issues |
Encoding: | UTF-8 |
Imports: | ggplot2 (≥ 3.5.0) |
RoxygenNote: | 7.3.2 |
Suggests: | testthat, vdiffr, covr |
NeedsCompilation: | no |
Packaged: | 2025-06-20 03:50:42 UTC; elio |
Author: | Elio Campitelli |
Maintainer: | Elio Campitelli <eliocampitelli@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-06-20 04:50:02 UTC |
ggnewscale: Multiple Fill and Colour Scales in 'ggplot2'
Description
Use multiple fill and colour scales in 'ggplot2'.
Usage
To have more than one colour or fill scale in a plot using ggplot2, you add a new scale slot with new_scale and the following geoms will use a different scale than the previous ones.
Author(s)
Maintainer: Elio Campitelli eliocampitelli@gmail.com (ORCID)
See Also
Useful links:
Report bugs at https://github.com/eliocamp/ggnewscale/issues
Adds a new scale to a plot
Description
Creates a new scale "slot". Geoms added to a plot after this function will use a new scale definition.
Usage
new_scale(new_aes)
new_scale_fill()
new_scale_color()
new_scale_colour()
Arguments
new_aes |
A string with the name of the aesthetic for which a new scale will be created. |
Details
new_scale_color()
, new_scale_colour()
and new_scale_fill()
are just
aliases to new_scale("color")
, etc...
Examples
library(ggplot2)
# Equivalent to melt(volcano), but we don't want to depend on reshape2
topography <- expand.grid(x = 1:nrow(volcano),
y = 1:ncol(volcano))
topography$z <- c(volcano)
# point measurements of something at a few locations
measurements <- data.frame(x = runif(30, 1, 80),
y = runif(30, 1, 60),
thing = rnorm(30))
ggplot(mapping = aes(x, y)) +
geom_contour(data = topography, aes(z = z, color = stat(level))) +
# Color scale for topography
scale_color_viridis_c(option = "D") +
# geoms below will use another color scale
new_scale_color() +
geom_point(data = measurements, size = 3, aes(color = thing)) +
# Color scale applied to geoms added after new_scale_color()
scale_color_viridis_c(option = "A")