README.md

ggreverse

ggreverse takes a ggplot object and returns the code to create that plot.

This package is written as a learning exercise to help me figure out the internal structure of a ggplot object.

Releases

Installation

You can install from GitHub with:

# install.packages("remotes")
remotes::install_github("coolbutuseless/ggreverse")

Example ggreverse::convert_to_code()

  1. Create a ggplot
  2. Convert the ggplot back into code using ggreverse
  3. Convert the code back into a plot
library(ggreverse)

plot_df <- mtcars

# Create a ggplot2 plot object
p <- ggplot(plot_df) +
  geom_point(aes(mpg, wt, colour = cyl), size = 3) +
  labs(title = "hello") +
  theme_bw() + 
  theme(legend.position = 'none') + 
  coord_equal()

# Convert the plot object back into code
plot_code <- ggreverse::convert_to_code(p)
print(plot_code)
#> ggplot(data = plot_df) +
#>   geom_point(mapping = aes(x = mpg, y = wt, colour = cyl), size = 3, position = position_identity(), stat = "identity") +
#>   labs(title = "hello", x = "mpg", y = "wt", colour = "cyl") +
#>   theme_bw(11) +
#>   theme(legend.position = "none") +
#>   coord_fixed()
# Parse the plot code back into a plot - which should match the original plot
eval(parse(text = plot_code))

Technical Notes

ToDo

SessionInfo

Developed against:



coolbutuseless/ggreverse documentation built on June 4, 2019, 5:12 p.m.