ggmethod: Build a method for gg objects

Description Usage Arguments Value Examples

Description

From a function applied on a data frame, build a function that can be applied on a gg object's data.#'

Usage

1

Arguments

f

function, often a data frame method when trying to build the corresponding gg method

Value

a function

Examples

 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()

moodymudskipper/ggfun documentation built on May 26, 2019, 3:33 p.m.