Remove geom(s) from an existing ggplot chart?

前端 未结 4 443
情深已故
情深已故 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:47

    Build the plot to have all the waiver() stuff (axis limits and labels, etc.) resolve, tamper with that, then convert it to a gtable for plotting.

    p_built <- ggplot_build(p)
    p_built$plot$layers[[1]] <- NULL
    p_built$data[[1]] <- NULL
    plot(ggplot_gtable(p_built))
    

    Note that you need to remove not only the layer but also the dataset for that layer.

提交回复
热议问题