hide_geoms: Hide geoms on plot while keeping legends and scaling intact

View source: R/ggplot_functions.R

hide_geomsR Documentation

Hide geoms on plot while keeping legends and scaling intact

Description

Hides all the geoms on the graph while keeping everything else (e.g., the scaling, the legends, the titles, etc.) the same.
Useful for when, in a talk, you want to explain to the audience what they are about to see, while acquainting them with the legends, etc.

Usage

hide_geoms(gg_obj)

Arguments

gg_obj

The ggplot object whose data you want to hide.

Details

Currently, this just goes through each layer of data and sets the size and alpha to 0. This hasn't been tested at edge cases.

Value

a gtable object (which you can plot)

Examples


a <- dplyr::tibble(
  alp=runif(120,0,3),
  bet=alp*2+1,
  gam=rbinom(120,1,0.5))
b <- dplyr::tibble(
  alp=runif(120,3,10),
  bet=-alp*2+10,
  gam=rbinom(120,1,0.5))
g <- a %>%
  ggplot2::ggplot(aes(x=alp,y=bet, color=as.factor(gam))) +
  ggplot2::geom_point() +
  ggplot2::geom_vline(xintercept = 5) +
  ggplot2::geom_line(data=b)
plot(g)
plot(hide_geoms(g))


burchill/zplyr documentation built on Feb. 2, 2023, 11:01 a.m.