minus-ggghost: Remove a call from a ggghost object

Description Usage Arguments Details Value Examples

Description

Calls can be removed from the ggghost object via regex matching of the function name. All matching calls will be removed based on the match to the string up to the first bracket, so any arguments are irrelevant.

Usage

1
2
## S3 method for class 'gg'
e1 - e2

Arguments

e1

An object of class ggghost

e2

A component to remove from e1

Details

For example, subtracting geom_line() will remove all calls matching geom_line regardless of their arguments.

'labs()' has been identified as a special case, as it requires an argument in order to be recognised as a valid function. Thus, trying to remove it with an empty argument will fail. That said, the argument doesn't need to match, so it can be populated with a dummy string or anything that evaluates in scope. See examples.

Value

A ggghost structure with calls matching e2 removed, otherwise the same as e1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## create a ggghost object
tmpdata <- data.frame(x = 1:100, y = rnorm(100))

z %g<% ggplot(tmpdata, aes(x,y))
z <- z + geom_point(col = "steelblue")
z <- z + theme_bw()
z <- z + labs(title = "My cool ggplot")
z <- z + labs(x = "x axis", y = "y axis")
z <- z + geom_smooth()

## remove the geom_smooth
z - geom_smooth()

## remove the labels
## NOTE: argument must be present and able to be 
## evaluated in scope
z - labs(TRUE) # works
z - labs(title) # works because of title(), but removes all labs()

jonocarroll/ggghost documentation built on May 19, 2019, 7:31 p.m.