View source: R/ggplot_functions.R
share_discrete_scales | R Documentation |
DEPRECATED AS HELL, please use share_scales
instead.
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_discrete_scales
lets you send identical arguments to a list of ggplot
functions you
specify. Note that you need to pipe the ggplot object into this function. If you don't put
this function immediately after invoking ggplot(...)
, the preceding objects should be added to the
ggplot
object with %+%
instead of +
.
share_discrete_scales(gg_obj, geom_func_list, ...)
gg_obj |
The ggplot object |
geom_func_list |
A vector or list of |
... |
Whatever arguments you want passed to these functions |
share_scales
## Not run: df <- data.frame( x=rnorm(100), f=c(rep("Label1",50), rep("Label2",50)) ) ggplot(df, aes(x = x, color=f, fill=f)) %+% geom_histogram() %>% share_discrete_scales(c(scale_color_discrete, scale_fill_discrete), name="Legend Label!", breaks=c("Label1","Label2"), labels=c("NewName1","NewName2")) + xlab("Name") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.