rgg: Remove and replace ggplot2 layers.

Description Usage Arguments Examples

View source: R/rgg.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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
}

Example output

Loading required package: ggplot2

ggedit documentation built on July 8, 2020, 5:34 p.m.