在R中将点图保存为pdf

编程入门 行业动态 更新时间:2024-10-08 20:40:39
本文介绍了在R中将点图保存为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在函数中执行此命令时,我无法将点图保存为pdf.

I am having trouble saving a dotplot to pdf when this command is done inside a function.

正常调用时效果很好:

df <- data.frame(a = runif(10), b = runif(10), c = runif(10), x = 1:10) pdf("test.pdf") dotplot(a + b + c ~ x, data = df, type = "l", auto.key=TRUE) dev.off()

但是,如果此代码位于函数内部,则它将无法正常工作,只会生成一个空文件或空文件:

But if this code is inside a function, it will not work and just makes an empty or blank file:

plotFunc <- function(model) { pdf("test.pdf") dotplot(a + b + c ~ x, data = model, type = "l", auto.key=TRUE) dev.off() } plotFunc(df)

但是,调用不带文件命令的函数将成功打印到图形窗口:

However, calling the function without the file commands will successfully print to the graphics window:

plotWinFunc <- function(model) { dotplot(a + b + c ~ x, data = model, type = "l", auto.key=TRUE) } plotWinFunc(df)

这使我相信dotplot()应该输出到文件时出了点问题.文件的类型无关紧要,我尝试使用bmp和pdf两种方法,但这两种方法均无效.

This leads me to believe that something goes wrong with dotplot() when it is supposed to output to a file. And the type of file doesn't matter, I have tried with both bmp and pdf and neither method works.

如何成功将点图写入文件?我必须使用从点阵软件包中得到的特殊命令还是在某个地方出现错误?

How can I successfully write a dotplot to a file? Do I have to use a special command from the lattice package or do I have an error somewhere?

感谢您的帮助.

推荐答案

我刚刚意识到我必须将dotplot包装在print()中:

Just realized I have to wrap dotplot in print():

plotFunc <- function(model) { pdf("test.pdf") print(dotplot(a + b + c ~ x, data = model, type = "l", auto.key=TRUE)) dev.off() } plotFunc(df)

这似乎已经解决了.

更多推荐

在R中将点图保存为pdf

本文发布于:2023-07-18 08:07:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   保存为   pdf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!