在 R 中重复绘图命令并进行微小更改
我在 R 中画了一个图,我想重复所有命令(例如 plot()
、legend()
或 line()
)对此情节进行了一些细微的改动。例如,我想将轴设置为对数刻度并更改绘图的标题。
在 gnuplot 中,我将使用 replot
命令。
plot ...
set title "The same plot with logarithmic axes"
set logscale
replot
在 R 中可能有这样的事情吗?我想到这样做的唯一一件事(除了手动更改值并重新运行代码行)是设置一个函数,该函数要求所有可能更改的参数由用户。
谢谢你的帮助,
斯文
I made a plot in R and I want to repeat all the commands (like plot()
, legend()
or line()
) that were carried out for this plot, with some minor changes. For example I want to set the axes to logarithmic scale and change the title of the plot.
In gnuplot I would use the replot
command.
plot ...
set title "The same plot with logarithmic axes"
set logscale
replot
Is something like this possible in R. The only thing that comes to my mind of doing this (besides changing the values manually and re-run the lines of codes) would be setting up a function, that asks for all parameters that might be changed by the user.
Thanks for your help,
Sven
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
R 使用笔和纸图形模型 - 一旦在设备上绘制了图就可以了。如果要更改绘图的某些方面,则需要重播生成绘图的图形函数调用以及对代码所做的更改。
根据您真正要做的事情,有两种选择:
Lattice 和 ggplot2 略有不同,因为它们基于网格图形并创建打印时在设备上生成绘图的对象。人们可以操纵该对象来改变所绘制的内容,并且使用网格可以将事物推入或弹出视口。
R uses a pen and paper graphics model - once the plot has been drawn on the device that is it. If you want to change some aspect of the plot, you need to replay the graphics function calls that produce the plot with the changes made to the code.
Depending on what you are really doing there are two options:
Lattice and ggplot2 are a little different as they are based on grid graphics and create objects that when printed produce a plot on the device. One can manipulate that object to alter what is drawn, and with grid one can push and pop things on to / off a viewport.