Remove geom(s) from an existing ggplot chart?

前端 未结 4 441
情深已故
情深已故 2020-12-15 21:28

I am trying to understand how I can make changes to the internals of a ggplot2 chart. I started reading the few ressources I could find about ggplot_built and <

4条回答
  •  隐瞒了意图╮
    2020-12-15 21:35

    You can use gginnards package to make life easier

    library(ggplot2)
    
    ### sample plot w/ both points and labels
    g <- ggplot(iris, aes(Petal.Length, Petal.Width)) + 
      geom_point() + 
      geom_text(aes(label = Sepal.Width))
    g
    

    ### https://cran.rstudio.com/web/packages/gginnards/vignettes/user-guide-2.html
    library(gginnards)
    
    ### remove points
    delete_layers(g, "GeomPoint")
    

    ### remove text
    delete_layers(g, "GeomText")
    

提交回复
热议问题