share_scales: Share arguments amongst multiple ggplot functions

View source: R/ggplot_functions.R

share_scalesR Documentation

Share arguments amongst multiple ggplot functions

Description

Often it is the case that one wishes to pass identical arguments to multiple functions in ggplot. For example, if one wants to scale both color and fill with the same breaks and legend names/labels.
The function share_scales lets you send identical arguments to a list of ggplot functions you specify.

Usage

share_scales(...)

Arguments

...

Unnamed arguments should be ggplot2 functions (e.g., scale_color_discrete, scale_fill_discrete, etc.) and named arguments should be whatever arguments you want passed to these functions

Value

A list of the ggproto objects

Examples

df <- data.frame(
   x<-rnorm(100),
   f<-c(rep("Label1",50), rep("Label2",50))
)

l <- c(1,2,3,4,5,6)
df <- data.frame(x = rgamma(100, 2, 2),
                 y = factor(sample(l, size=100, replace = TRUE)))

  ggplot(df, aes(x=x, y=y, size=y, color=y, fill=y, shape=y)) +
  geom_point() +
  # Zplyr function
  share_scales(scale_color_discrete,  scale_size_discrete,
               scale_fill_discrete, scale_shape_discrete,
               name="Legend Label!",
               breaks=c(1,2,3,4,5,6),
               labels=c("uno","dos","tres","catorce","FIVE","siiiiiix"))

burchill/zplyr documentation built on Feb. 2, 2023, 11:01 a.m.