How to see the code of the saved plot (ggplot)

I want to know if it is possible to see the code of the graph that is stored in a variable. For example, given the following graph:

library(ggplot2)

myData <- data.frame(x=1:100, y = 100:1)
myPlot <- ggplot(myData, aes(x,y)) + geom_line()

I would like to have a "seeCode" function that returns the actual code used to plot the graph:

>seeCode(myPlot)
  ggplot(myData, aes(x,y)) + geom_line()
+4
source share
1 answer

This information is not saved. There is no one-to-one mapping from the ggplot object to the code that created it, just as there is no way to know if a "5" came from a "3 + 2" or a "4 + 1".

+4
source

All Articles