Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
R
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ggnewscale

R build status Codecov test coverage DOI CRAN status

ggnewscale tries to make it painless to use multiple scales in ggplot2. Although originally intended to use with colour and fill, it should work with any aes, such as shape, linetype and the rest. It’s very experimental, so use at your own risk!

For another way of defining multiple scales, you can also try relayer.

How to install

You can install ggnewscale from CRAN with:

install.packages("ggnewscale")

Or the development version with:

# install.packages("devtools")
devtools::install_github("eliocamp/ggnewscale")

How to cite

If you use ggnewscale in a publication, I’ll be grateful if you cited it. To get the suggested citation for this (and any other R package) you can use:

citation("ggnewscale")
#> 
#> To cite ggnewscale in publications use:
#> 
#> Campitelli E (2021). _ggnewscale: Multiple Fill and Colour Scales in
#> 'ggplot2'_. doi: 10.5281/zenodo.2543762 (URL:
#> https://doi.org/10.5281/zenodo.2543762), R package version 0.4.5.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Manual{R-ggnewscale,
#>     title = {ggnewscale: Multiple Fill and Colour Scales in 'ggplot2'},
#>     author = {Elio Campitelli},
#>     year = {2021},
#>     note = {R package version 0.4.5},
#>     doi = {10.5281/zenodo.2543762},
#>   }

If you use knitr, you can automate this with

knitr::write_bib(c("ggnewscale"), "packages.bib")

And then add citations with @R-ggnewscale.

Click to see a list of some publications that have cited ggnewscale. Thanks!

[1] R. AminiTabrizi, R. M. Wilson, J. D. Fudyma, et al. “Controls on Soil Organic Matter Degradation and Subsequent Greenhouse Gas Emissions Across a Permafrost Thaw Gradient in Northern Sweden”. In: Front. Earth Sci. 8 (2020). ISSN: 2296-6463. DOI: 10.3389/feart.2020.557961.

[2] M. C. Granovetter, L. Ettensohn, and M. Behrmann. “With Childhood Hemispherectomy, One Hemisphere Can Support—But Is Suboptimal for—Word and Face Recognition”. En. In: bioRxiv (nov. 2020), p. 2020.11.06.371823. DOI: 10.1101/2020.11.06.371823.

[3] M. Jung, D. Wells, J. Rusch, et al. “Unified Single-Cell Analysis of Testis Gene Regulation and Pathology in Five Mouse Strains”. In: eLife 8 (jun. 2019). Ed. by D. Bourc’his, P. J. Wittkopp and S. Lukassen, p. e43966. ISSN: 2050-084X. DOI: 10.7554/eLife.43966.

[4] A. Lan, K. Kang, S. Tang, et al. “Fine-Scale Population Structure and Demographic History of Han Chinese Inferred from Haplotype Network of 111,000 Genomes”. En. In: bioRxiv (jul. 2020), p. 2020.07.03.166413. DOI: 10.1101/2020.07.03.166413.

[5] E. Merino Tejero, D. Lashgari, R. Garc'ia-Valiente, et al. “Multiscale Modeling of Germinal Center Recapitulates the Temporal Transition From Memory B Cells to Plasma Cells Differentiation as Regulated by Antigen Affinity-Based Tfh Cell Help”. In: Front Immunol 11 (feb. 2021). ISSN: 1664-3224. DOI: 10.3389/fimmu.2020.620716.

[6] G. Papacharalampous, H. Tyralis, S. M. Papalexiou, et al. “Global-Scale Massive Feature Extraction from Monthly Hydroclimatic Time Series: Statistical Characterizations, Spatial Patterns and Hydrological Similarity”. En. In: Science of The Total Environment 767 (may. 2021), p. 144612. ISSN: 0048-9697. DOI: 10.1016/j.scitotenv.2020.144612.

[7] A. Rutz, M. Sorokina, J. Galgonek, et al. “Open Natural Products Research: Curation and Dissemination of Biological Occurrences of Chemical Structures through Wikidata”. En. In: bioRxiv (mar. 2021), p. 2021.02.28.433265. DOI: 10.1101/2021.02.28.433265.

[8] O. Seppälä. “Spatial and Temporal Drivers of Soil Respiration in a Tundra Environment”. En. PhD thesis. FACULTY OF SCIENCE DEPARTMENT OF GEOSCIENCES AND GEOGRAPHY GEOGRAPHY: UNIVERSITY OF HELSINKI, 2020.

[9] C. C. Smith, S. Entwistle, C. Willis, et al. “Landscape and Selection of Vaccine Epitopes in SARS-CoV-2”. In: bioRxiv (jun. 2020). DOI: 10.1101/2020.06.04.135004.

[10] A. Torres-Esp'in, A. Chou, J. R. Huie, et al. “Reproducible Analysis of Disease Space via Principal Components Using the Novel R Package syndRomics”. In: eLife 10 (ene. 2021). Ed. by M. Zaidi and M. Barton, p. e61812. ISSN: 2050-084X. DOI: 10.7554/eLife.61812.

[11] R. J. Wright, M. G. I. Langille, and T. R. Walker. “Food or Just a Free Ride? A Meta-Analysis Reveals the Global Diversity of the Plastisphere”. En. In: The ISME Journal 15.3 (mar. 2021), pp. 789-806. ISSN: 1751-7370. DOI: 10.1038/s41396-020-00814-9.

[12] A. Yan, J. Butcher, D. Mack, et al. “Virome Sequencing of the Human Intestinal MucosalInterface”. In: Front Cell Infect Microbiol 10 (oct. 2020). ISSN: 2235-2988. DOI: 10.3389/fcimb.2020.582187.

Usage

The main function is new_scale() and its aliases new_scale_color() and new_scale_fill(). When added to a plot, every geom added after them will use a different scale.

As an example, let’s overlay some measurements over a contour map of topography using the beloved volcano.

library(ggplot2)
library(ggnewscale)
# Equivalent to melt(volcano)
topography <- expand.grid(x = 1:nrow(volcano),
                          y = 1:ncol(volcano))
topography$z <- c(volcano)

# point measurements of something at a few locations
set.seed(42)
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")

If you want to create new scales for other aes, you can call new_scale with the name of the aes. For example, use

new_scale("linetype")

to add multiple linetype scales.

About

Multiple Fill, Color and Other Scales in `ggplot2`

Resources

License

Packages

No packages published