R中的savePlot()错误消息:只能从“ Windows”设备复制

Gil*_*syn 1 windows r rstudio

在Windows 8系统上使用RStudio会显示以下错误消息:

Error in savePlot(filename = "123", type = c("png"), device = dev.cur()) : 
  can only copy from 'windows' devices
Run Code Online (Sandbox Code Playgroud)

如果我windows()在savePlot之前的行中写入,错误消息消失,但该图为“空”。如果我使用R代替RStudio,则不存在该问题。

除了“不使用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)
Run Code Online (Sandbox Code Playgroud)

我在哪里以及如何在此处分别使用png和win.metafile函数?它可以在R中使用,但不能在RStudio中使用...

Fed*_*ina 5

您可以使用png功能。例如:

png(filename = "testPlot.png", width = 480, height = 480)
plot(1:10, type = 'l')
dev.off()
Run Code Online (Sandbox Code Playgroud)

在其中filename,应定义绘图的路径。