Description Usage Arguments Value Examples
From a function applied on a data frame, build a function that can be applied on a gg object's data.#'
1 | ggmethod(f)
|
f |
function, often a data frame method when trying to build the corresponding gg method |
a function
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 | library(ggplot2)
library(dplyr)
mutate.gg <- ggmethod(dplyr::mutate)
ggplot(iris,aes(Sepal.Length)) +
geom_point(aes(y=SL2)) %>%
dplyr::mutate(SL2 = sin(Sepal.Length), Sepal.Length = Sepal.Length*10) +
theme_minimal()
# better to define from data.frame method to have explicit parameters
# but it works just the same
head.gg <- ggmethod(head)
formals(head.gg)
head.gg <- ggmethod(utils:::head.data.frame)
formals(head.gg)
# apply on waiver
ggplot(iris,aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point() %>%
head() +
theme_minimal()
# apply on data
ggplot(NULL,aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(data=iris) %>%
head() +
theme_minimal()
# apply on function
ggplot(iris,aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(data=identity) %>%
head() +
theme_minimal()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.