如何查看存储图的代码 (ggplot)

How to see the code of a stored plot (ggplot)

我想知道是否可以查看存储在变量中的绘图代码。例如,给定以下图:

library(ggplot2)

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

我想要一个函数 "seeCode" returns 用于构建情节的实际代码:

>seeCode(myPlot)
  ggplot(myData, aes(x,y)) + geom_line()

该信息未保留。没有从 ggplot 对象到生成它的代码的一对一映射,就像无法知道“5”是来自“3+2”还是“4+1”一样。