如何查看存储图的代码(ggplot) [英] How to see the code of a stored plot (ggplot)
本文介绍了如何查看存储图的代码(ggplot)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以查看存储在变量中的绘图的代码.例如,给定以下图:
I want to know whether it is possible to see the code of a plot that is stored in a variable. For example, given the following plot:
library(ggplot2)
myData <- data.frame(x=1:100, y = 100:1)
myPlot <- ggplot(myData, aes(x,y)) + geom_line()
我想要一个函数"seeCode",该函数返回用于构建绘图的实际代码:
I'd like to have a function "seeCode" that returns the actual code used to construct the plot:
>seeCode(myPlot)
ggplot(myData, aes(x,y)) + geom_line()
推荐答案
该信息未保留.没有从ggplot对象到生成它的代码的一对一映射,就像无法知道"5"是来自"3 + 2"还是"4 + 1"一样.
That information isn't retained. There's not a one-to-one mapping from ggplot object to the code that produced it, just as there's no way to know if a "5" came from "3+2" or "4+1".
这篇关于如何查看存储图的代码(ggplot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文