Description Usage Arguments Value Examples
Generate code to create a ggplot2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
data |
Character. Name of the |
mapping |
List. Named list of aesthetics. |
geom |
Character. Name of the geom to use (with or without "geom_"). |
geom_args |
List. Arguments to use in the geom. |
scales |
Character vector. Scale(s) to use (with or without "scale_"). |
scales_args |
List. Arguments to use in scale(s),
if |
coord |
Character. Coordinates to use (with or without "coord_"). |
labs |
List. Named list of labels to use for title, subtitle, x & y axis, legends. |
theme |
Character. Name of the theme to use (with or without "theme_"). |
theme_args |
Named list. Arguments for |
facet |
Character vector. Names of variables to use in |
facet_row |
Character vector. Names of row variables to use in |
facet_col |
Character vector. Names of col variables to use in |
facet_args |
Named list. Arguments for |
xlim |
A vector of length 2 representing limits on x-axis. |
ylim |
A vector of length 2 representing limits on y-axis. |
a call
that can be evaluated with eval
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # Default:
ggcall()
# With data and aes
ggcall("mtcars", list(x = "mpg", y = "wt"))
# Evaluate the call
library(ggplot2)
eval(ggcall("mtcars", list(x = "mpg", y = "wt")))
# With a geom:
ggcall(
data = "mtcars",
mapping = list(x = "mpg", y = "wt"),
geom = "point"
)
# With options
ggcall(
data = "mtcars",
mapping = list(x = "hp", y = "cyl", fill = "color"),
geom = "bar",
coord = "flip",
labs = list(title = "My title"),
theme = "minimal",
facet = c("gear", "carb"),
theme_args = list(legend.position = "bottom")
)
# Theme
ggcall(
"mtcars", list(x = "mpg", y = "wt"),
theme = "theme_minimal",
theme_args = list(
panel.ontop = TRUE,
legend.title = rlang::expr(element_text(face = "bold"))
)
)
# Theme from other package than ggplot2
ggcall(
"mtcars", list(x = "mpg", y = "wt"),
theme = "ggthemes::theme_economist"
)
# One scale
ggcall(
data = "mtcars",
mapping = list(x = "mpg", y = "wt", color = "qsec"),
geom = "point",
scales = "color_distiller",
scales_args = list(palette = "Blues")
)
# Two scales
ggcall(
data = "mtcars",
mapping = list(x = "mpg", y = "wt", color = "qsec", size = "qsec"),
geom = "point",
scales = c("color_distiller", "size_continuous"),
scales_args = list(
color_distiller = list(palette = "Greens"),
size_continuous = list(range = c(1, 20))
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.