minus-ggghost: Remove a call from a ggghost object

-.ggR 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 ggghost

e2

A component to remove from e1 as either a string or a language object

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

z - "labs"        # removes all labs
z - "title"       # removes just the title
z - "axis"        # removes the axis labels
z - geom_point()  # removes points
z - theme_bw()    # removes theme_bw()

ggghost documentation built on June 30, 2025, 9:07 a.m.