-.gg {ggghost} | R Documentation |
Remove a call from a ggghost object
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
## S3 method for class 'gg'
e1 - e2
Arguments
e1 |
An object of class |
e2 |
A component to remove from |
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
## 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()