Learn R Programming

thisplot (version 0.3.1)

slim_data: Slim unused data in the plot

Description

Remove unused columns from the data in a ggplot or patchwork object. This function keeps only the columns that are actually used in the plot (e.g., in mappings, aesthetics, or facets), which can significantly reduce the object size when the original data contains many unused columns.

Usage

slim_data(p)

# S3 method for ggplot slim_data(p)

# S3 method for patchwork slim_data(p)

Value

A ggplot or patchwork object with unused data columns removed.

Arguments

p

A ggplot object or a patchwork object.

Examples

Run this code
library(ggplot2)
p <- ggplot(
  data = mtcars,
  aes(x = mpg, y = wt, colour = cyl)
) +
  geom_point()
object.size(p)
colnames(p$data)

p_slim <- slim_data(p)
object.size(p_slim)
colnames(p_slim$data)

Run the code above in your browser using DataLab