R 中的 savePlot() 错误消息:只能从 'windows' 设备复制
savePlot() error message in R: can only copy from 'windows' devices
在 Windows 8 系统上使用 RStudio 时出现以下错误消息:
Error in savePlot(filename = "123", type = c("png"), device = dev.cur()) :
can only copy from 'windows' devices
如果我在 savePlot 之前的行中写 windows()
,错误消息就会消失,但绘图是 "empty"。
如果我使用 R 而不是 RStudio,则问题不存在。
除了"not using RStudio"还有其他解决办法吗?
最好的问候
编辑:
这里有更多的原始代码:
#--------------create plot
x <- df$Year
y <- df$Index1970
par(family="serif", font=1, cex=1)
xrange <- range(x, na.rm=TRUE)
yrange <- range(y, na.rm=TRUE)
plot(xrange, yrange, type="n", xlab="Year",
ylab="Price index, 1970=100" )
lines(x, y, col="black", lwd=3)
title("Belgium Property Prices from 1970-2013")
grid(nx = NULL, ny = NULL, col = "lightgray", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
savePlot(filename="D:/...RPlots/Belgium_Prices_from_1970-2013",
type=c("wmf"),
device=dev.cur(), #type=c("wmf", "png", "jpeg", "jpg", "bmp", "ps", "pdf")
restoreConsole = TRUE)
我在哪里以及如何使用 png,这里分别是 win.metafile 功能?
它适用于 R,但不适用于 RStudio...
您可以使用png
功能。例如:
png(filename = "testPlot.png", width = 480, height = 480)
plot(1:10, type = 'l')
dev.off()
在 filename
中,您应该定义绘图的路径。
当我使用 RStudio 时,我的第一个绘图具有 "RStudio" 类型而不是 "windows" 类型。下一个地块具有正确的 "window" 类型。
所以我在我的第一个 "saveplot" 之前调用了这个函数(见下文)并且它起作用了......
#
# Initialise les fenêtres pour RStudio
# La première fenêtre créée n'est pas toujours du type "windows", il faut en recréer une
#
init_fenetres <- function()
{
dev.new()
numFenetre = dev.cur()
mx = as.matrix(dev.cur())
if (rownames(mx)[1] != "windows") {
dev.new()
numFenetre = dev.cur()
}
dev.off( numFenetre )
}
在 Windows 8 系统上使用 RStudio 时出现以下错误消息:
Error in savePlot(filename = "123", type = c("png"), device = dev.cur()) :
can only copy from 'windows' devices
如果我在 savePlot 之前的行中写 windows()
,错误消息就会消失,但绘图是 "empty"。
如果我使用 R 而不是 RStudio,则问题不存在。
除了"not using RStudio"还有其他解决办法吗? 最好的问候
编辑: 这里有更多的原始代码:
#--------------create plot
x <- df$Year
y <- df$Index1970
par(family="serif", font=1, cex=1)
xrange <- range(x, na.rm=TRUE)
yrange <- range(y, na.rm=TRUE)
plot(xrange, yrange, type="n", xlab="Year",
ylab="Price index, 1970=100" )
lines(x, y, col="black", lwd=3)
title("Belgium Property Prices from 1970-2013")
grid(nx = NULL, ny = NULL, col = "lightgray", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
savePlot(filename="D:/...RPlots/Belgium_Prices_from_1970-2013",
type=c("wmf"),
device=dev.cur(), #type=c("wmf", "png", "jpeg", "jpg", "bmp", "ps", "pdf")
restoreConsole = TRUE)
我在哪里以及如何使用 png,这里分别是 win.metafile 功能? 它适用于 R,但不适用于 RStudio...
您可以使用png
功能。例如:
png(filename = "testPlot.png", width = 480, height = 480)
plot(1:10, type = 'l')
dev.off()
在 filename
中,您应该定义绘图的路径。
当我使用 RStudio 时,我的第一个绘图具有 "RStudio" 类型而不是 "windows" 类型。下一个地块具有正确的 "window" 类型。 所以我在我的第一个 "saveplot" 之前调用了这个函数(见下文)并且它起作用了......
#
# Initialise les fenêtres pour RStudio
# La première fenêtre créée n'est pas toujours du type "windows", il faut en recréer une
#
init_fenetres <- function()
{
dev.new()
numFenetre = dev.cur()
mx = as.matrix(dev.cur())
if (rownames(mx)[1] != "windows") {
dev.new()
numFenetre = dev.cur()
}
dev.off( numFenetre )
}