### Install ggnewscale Development Version Source: https://eliocamp.github.io/ggnewscale/index.html Install the latest development version of ggnewscale directly from GitHub using the devtools package. This is useful for accessing the newest features or bug fixes. ```r # install.packages("devtools") devtools::install_github("eliocamp/ggnewscale") ``` -------------------------------- ### Install ggnewscale from CRAN Source: https://eliocamp.github.io/ggnewscale/index.html Use this command to install the stable version of the ggnewscale package from the Comprehensive R Archive Network (CRAN). ```r install.packages("ggnewscale") ``` -------------------------------- ### Interactive Program Startup Notice (GNU GPL) Source: https://eliocamp.github.io/ggnewscale/LICENSE.html This notice should be displayed by programs interacting via terminal when they start. It informs users about the lack of warranty and the conditions for redistribution under the GNU GPL. Commands like 'show w' and 'show c' are placeholders for displaying license details. ```text ggnewscale Copyright (C) 2018 Elio Campitelli This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Create and Rename AES Mappings Source: https://eliocamp.github.io/ggnewscale/reference/rename_aes.html Use `rename_aes()` to map a new name to an existing aesthetic. Use `clear_aes()` to remove all previous aesthetic mappings before adding new ones. This example demonstrates how to create a contour plot with a color aesthetic named 'topo_color' and then add a point plot with a different color aesthetic. ```R 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)) + rename_aes(topo_color = "color") + geom_contour(data = topography, aes(z = z, topo_color = stat(level))) + # Color scale for topography scale_color_viridis_c(option = "D") + clear_aes() + # geoms below will use another color scale geom_point(data = measurements, size = 3, aes(colour = thing)) + # Color scale applied to geoms added after new_scale_color() scale_color_viridis_c(option = "A") #> Warning: Ignoring unknown aesthetics: topo_colour ``` -------------------------------- ### Get Citation for ggnewscale Package Source: https://eliocamp.github.io/ggnewscale/index.html Use this R command to retrieve the suggested citation for the ggnewscale package, including both a standard format and a BibTeX entry for LaTeX users. ```r citation("ggnewscale") #> To cite ggnewscale in publications use: #> #> Campitelli E (????). _ggnewscale: Multiple Fill and Colour Scales in #> 'ggplot2'_. doi:10.5281/zenodo.2543762 #> , R package version 0.5.2. #> #> A BibTeX entry for LaTeX users is #> #> @Manual{R-ggnewscale, #> title = {ggnewscale: Multiple Fill and Colour Scales in 'ggplot2'}, #> author = {Elio Campitelli}, #> note = {R package version 0.5.2}, #> doi = {10.5281/zenodo.2543762}, #> } ``` -------------------------------- ### Example: Multiple Color Scales in ggplot2 Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Demonstrates using `new_scale_color()` to apply two different color scales to different geoms within the same plot. The first scale is for contour lines, and the second is for points. ```r 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") #> Warning: `stat(level)` was deprecated in ggplot2 3.4.0. #> ℹ Please use `after_stat(level)` instead. ``` -------------------------------- ### clear_aes Source: https://eliocamp.github.io/ggnewscale/reference/rename_aes.html Clears all existing aesthetic mappings. This function is useful for resetting scales or starting fresh with new aesthetic definitions. ```APIDOC ## clear_aes ### Description Clears all existing aesthetic mappings. ### Usage ```R clear_aes() ``` ``` -------------------------------- ### S3 method for class 'ggplot_rename_next' Source: https://eliocamp.github.io/ggnewscale/reference/plus-.ggplot_rename_next.html This S3 method allows you to add elements like layers, scales, or guides to a ggplot object. ```APIDOC ## S3 method for class 'ggplot_rename_next' ### Description Adds an element to a ggplot object. ### Method `+` operator (S3 method) ### Arguments * **e1** (ggplot_rename_next) - The ggplot object to which the element will be added. * **e2** (layer, scale, guides, list of layers) - The element to add to the plot. ``` -------------------------------- ### Add element to ggplot with new scales Source: https://eliocamp.github.io/ggnewscale/reference/plus-.ggplot_rename_next.html Use the `+` operator to add elements like layers, scales, or guides to a ggplot object that has new scales defined. This method is part of the `ggplot_rename_next` S3 class. ```R e1 + e2 ``` -------------------------------- ### Standard GNU GPL Notice for Source Files Source: https://eliocamp.github.io/ggnewscale/LICENSE.html Include this notice at the beginning of each source file to state the exclusion of warranty and specify licensing terms under the GNU GPL version 3 or later. Ensure copyright and contact information are present. ```text Copyright (C) 2018 Elio Campitelli This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### rename_aes() Source: https://eliocamp.github.io/ggnewscale/reference/index.html Creates a new aesthetic mapping. ```APIDOC ## rename_aes() ### Description Creates a new aesthetic mapping. ### Usage ```r rename_aes(x) ``` ### Arguments * `x`: The aesthetic to rename. ``` -------------------------------- ### Create a New Fill Scale Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Aliases for `new_scale("fill")` to easily create a new fill scale. ```r new_scale_fill() ``` -------------------------------- ### Create a New Color Scale Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Aliases for `new_scale("color")` to easily create a new color scale. ```r new_scale_color() ``` -------------------------------- ### Create a New Colour Scale Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Aliases for `new_scale("color")` to easily create a new colour scale (alternative spelling). ```r new_scale_colour() ``` -------------------------------- ### Overlaying Topography and Measurements with New Color Scales Source: https://eliocamp.github.io/ggnewscale/index.html Demonstrates how to overlay contour map data with point measurements using separate color scales for each. Use `new_scale_color()` to introduce a new color scale for subsequent geoms. ```R 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") ``` -------------------------------- ### Automate Citation Generation with knitr Source: https://eliocamp.github.io/ggnewscale/index.html This R command, when used with knitr, automatically writes a BibTeX file named 'packages.bib' containing the citation information for the specified R packages. ```r knitr::write_bib(c("ggnewscale"), "packages.bib") ``` -------------------------------- ### rename_aes Source: https://eliocamp.github.io/ggnewscale/reference/rename_aes.html Creates a new aes mapping, supporting explicit renaming of an aesthetic. This is a focused version of `new_scale()`. ```APIDOC ## rename_aes ### Description Supports explicit rename of an aesthetic mapping. This is a slightly more focused version of `new_scale()`. ### Usage ```R rename_aes(...) ``` ### Arguments - `...`: name-value pair with the new name of the aes and the original name it's replacing. ``` -------------------------------- ### new_scale_colour Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Alias for `new_scale("colour")`. ```APIDOC ## new_scale_colour() ### Description Alias for `new_scale("colour")`. ### Details This function is an alias for `new_scale("colour")`. ``` -------------------------------- ### new_scale_fill Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Alias for `new_scale("fill")`. ```APIDOC ## new_scale_fill() ### Description Alias for `new_scale("fill")`. ### Details This function is an alias for `new_scale("fill")`. ``` -------------------------------- ### new_scale_color Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Alias for `new_scale("color")`. ```APIDOC ## new_scale_color() ### Description Alias for `new_scale("color")`. ### Details This function is an alias for `new_scale("color")`. ``` -------------------------------- ### Adding a New Linetype Scale with new_scale() Source: https://eliocamp.github.io/ggnewscale/index.html Introduces a new scale for the 'linetype' aesthetic using the generic `new_scale()` function. This allows for multiple linetype scales within the same plot. ```R new_scale("linetype") ``` -------------------------------- ### clear_aes() Source: https://eliocamp.github.io/ggnewscale/reference/index.html Clears all aesthetic mappings from a plot. ```APIDOC ## clear_aes() ### Description Clears all aesthetic mappings from a plot. ### Usage ```r clear_aes() ``` ``` -------------------------------- ### Define a New Scale for an Aesthetic Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Use `new_scale()` to create a new scale slot for a specified aesthetic. Geoms added after this function will use this new scale definition. ```r new_scale(new_aes) ``` -------------------------------- ### new_scale Source: https://eliocamp.github.io/ggnewscale/reference/new_scale.html Creates a new scale "slot". Geoms added to a plot after this function will use a new scale definition. ```APIDOC ## new_scale(new_aes) ### Description Creates a new scale "slot". Geoms added to a plot after this function will use a new scale definition. ### Arguments * **new_aes** (string) - 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 aliases for `new_scale("color")`, `new_scale("colour")`, and `new_scale("fill")` respectively. ``` -------------------------------- ### new_scale_fill() Source: https://eliocamp.github.io/ggnewscale/reference/index.html Adds a new fill scale to a plot. ```APIDOC ## new_scale_fill() ### Description Adds a new fill scale to a plot. ### Usage ```r new_scale_fill(aes = NULL, ...) ``` ### Arguments * `aes`: Aesthetic mapping for the new fill scale. * `...`: Additional arguments passed to the fill scale function. ``` -------------------------------- ### new_scale() Source: https://eliocamp.github.io/ggnewscale/reference/index.html Adds a new scale to a plot, allowing for custom color or fill scales. ```APIDOC ## new_scale() ### Description Adds a new scale to a plot. ### Usage ```r new_scale(aes = NULL, ...) ``` ### Arguments * `aes`: Aesthetic mapping for the new scale. * `...`: Additional arguments passed to the scale function. ``` -------------------------------- ### new_scale_color() Source: https://eliocamp.github.io/ggnewscale/reference/index.html Adds a new color scale to a plot. ```APIDOC ## new_scale_color() ### Description Adds a new color scale to a plot. ### Usage ```r new_scale_color(aes = NULL, ...) ``` ### Arguments * `aes`: Aesthetic mapping for the new color scale. * `...`: Additional arguments passed to the color scale function. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.