
Last chance! 50% off unlimited learning
Sale ends in
Removes specified layers from a ggplot object.
remove_geom(p, geom, idx = NULL)
ggplot2 plot object
character string of the name of the layer to remove
numeric of which index of geom to remove, Default: 1
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
pnew <- p |> remove_geom('point',1)
pnew
Run the code above in your browser using DataLab