ggloop's main function is
ggloop(), and it allows the user to create one of two things:
Instead of passing a single aesthetic (
ggplot(), the user can pass multiple aesthetics by using a vector of aesthetics. "Remapping"" behaviors control how the
y vectors are paired with one another, and they control how mutliple
... arguments are paired with
gg_obs argument controls the returned value: either
ggplot2 plots or a list of aesthetics which can be used to make
gg_obs's default value is
TRUE, which instructs
ggloop() to return plots.
ggloop() to return a list of aesthetics.
ggplot()'s arguments (for the most part).
data= Same as
mappings= Same as
aes_loop()is used in place of
aes(). There currently is no support for a "strings"-type function.
remap_xy= Controls the "remapping" behavior of the
yvectors. Default =
TRUE; other options include
TRUE= acts like
expand.grid()except that exact duplicates (i.e.
x <- mpg; y <- mpg) and unordered-pair duplicates (i.e.
x <- mpg; y <- cyland
x <- cyl; y <- mpg) are removed.
FALSE= acts like R's internal recycling mechanism, which replicates the shorter of the two vectors however many times necessary to pair with the longer vector.
NA= leaves an unpaired vector element unpaired (i.e.
x = (mpg, wt, hp); y = (cyl, gear)produces
x <- hpwith no y mapping)
remap_dots= Controls the "remapping" behavior of the
dotsarguments. Default =
FALSE; other option is
TRUE= acts like R's internal recycling mechanism, which replicates the shorter of the two vectors however many times necessary to pair with the longer vector.
FALSE= leaves un unpaired vecotr element unpaired; similar to
remap_xy = NAbehavior.
gg_obs= Controls the returned value.
FALSEreturns a list of aesthetics (see Value).
...= The same as
...; directly passed to
environment= The same as
environment; directly passed into
There are two main types of returned values when
gg_obs = TRUE:
ggplot2plots - when no
...are specified in
ggplot2plots - when there are
dplyr's syntax to call variables (i.e.
y = mpg:cyl,
x = 1:5, etc). You can still use
ggplot2's syntax to call variables (i.e.
x = disp,
x = mpg/hp,
color = factor(cyl),
y = gear + cyl, etc). You can also use both within a vector, but do adhere to the rule below.
c()and not have any other
c()within that wrapping (i.e.
x = c(mpg:cyl, 5, 6:8, gear + cyl, mpg/hp),
color = c(factor(cyl), factor(gear))).
x= Same as
y= Same as
...= Same as
magrittr-like implementation. Can be used to add to three different types of objects:
The user thus has the ability to add components to a subset of plots. Much like
+, the results of
%L+% will not be saved unless they are assigned.
Example: Using the
mtcars data set, create and plot all possible xy-pairs between
Steps: Load the necessary packages, create plots with
ggloop(), and add to plots using
library(ggplot2) library(ggloop) g <- ggloop(mtcars, aes_loop(x = mpg:hp, y = mpg:hp))
View some of the plots.
g$x.mpg_y.hp %L+% geom_point() g$x.cyl_y.disp %L+% geom_point() g$x.disp_y.hp %L+% geom_point() %L+% geom_line()
%L+% to add to two plots, save the output, and then display the results.
g[1:2] <- g[1:2] %L+% geom_point() g[1:2]
Look at the mappings of each name in
g. Note how the list is NOT nested (because no
... were called in
lapply(g, `[[`, "mapping")
c(mpg, disp, hp) against
wt and facet the resulting plots.
Steps: Create plots, add geoms, and add
g2 <- ggloop(mtcars, aes_loop(x = c(mpg, disp, hp), y = wt, color = factor(cyl))) %L+% geom_point() %L+% facet_grid(. ~ cyl)
View some plots
Look at the mappings of each name in
g2. Note how the list is nested (because a
... argument was called in
lapply(g2, function(x) lapply(x, `[[`, "mapping"))
Example: Return the list of aesthetics rather than the list of plots.
gg_obs = FALSE.
g3 <- ggloop(mtcars, aes_loop(x = c(mpg, disp, hp), y = wt, color = c(factor(cyl), factor(gear))), gg_obs = FALSE) print(g3)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.