【发布时间】:2022-05-17 19:45:52
【问题描述】:
我正在使用 Windows。尝试在 png 设备上绘制图形时,失败并出现错误。
我的代码:
png("C:\\plot1.png", width = 480, height = 480, units = "px", bg = "white")
par(mar= c(4, 4, 2, 1))
hist(pwrcon$Global_active_power,col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)")
dev.off()
错误:
Error in png("C:\\plot1.png", width = 480, height = 480, units = "px", :
unable to start png() device
In addition: Warning messages:
1: In png("C:\\plot1.png", width = 480, height = 480, units = "px", :
unable to open file 'C:\plot1.png' for writing
2: In png("C:\\plot1.png", width = 480, height = 480, units = "px", :
opening device failed
谁能帮我解决这个问题?
提前致谢
【问题讨论】:
-
@R.Schifini,您是否在编辑时添加了额外的反斜杠?如果是这样(并且如果您在下面的诊断是正确的),那么您已经使这个问题变得非常混乱......
-
@BenBolker,我只格式化了代码。我同意这令人困惑,但我记得只看到一个反斜杠。看来问题是通过重新安装解决的。我会投票赞成删除整个问题,因为它似乎没有进一步的用途。 (编辑:我什至复制了原始路径和文件名)
-
好的,投票结束。
-
是的,这个错误很可能是由于我们尝试写入png的
filename中的一个错误或不存在的文件夹目录引起的。我们计划使用的文件夹应该提前创建(使用例如if(!dir.exist(folder_name) dir.create(folder_name))。
标签: r