R: Remove and replace ggplot2 layers.

rgg {ggedit} | R Documentation

## Remove and replace ggplot2 layers.

### Description

Removes specified layers from a ggplot object and gives the option to replace them with a new layer. This layer can be either a geom object created from regular ggplot functions or an output from the ggedit gadget. In the latter case the layers are found in the updatedLayers object in the ggedit output.

### Usage

    rgg(p, oldGeom, oldGeomIdx = 1, newLayer = NULL)

### Arguments

`p` | ggplot2 plot object
`oldGeom` | character string of the name of the layer to remove
`oldGeomIdx` | numeric of which index of OldGeom to remove (default is 1)
`newLayer` | ggplot layer or list of layers

### Examples

    p <- ggplot2::ggplot(iris,ggplot2::aes(x =Sepal.Length,y=Sepal.Width))

    p <- p+ggplot2::geom_point(ggplot2::aes(colour=Species))+ggplot2::geom_line()

    p

    p%>%rgg('point',1)

    if( interactive() ){
    x <- ggedit(p)
    pnew <- p%>%rgg('point',1,x$updatedLayers[[1]])
    pnew
    }

[Package ggedit version 0.3.0 Index]