ggsave png错误与较大的大小 [英] ggsave png error with larger size
问题描述
<$我保存了一个刻面的ggplot2图,该图可以很好地保存在较小的尺寸上,但在我想增加它时会失败。 C $ C>> ggsave(tst.png,height = 6.75,width = 9)
#正常工作
> ggsave(tst.png,height = 9,width = 12)
grDevices :: png错误(...,width = width,height = height,res = dpi,:
无法启动设备
此外:警告消息:
1:在grDevices :: png(...,width = width,height = height,res = dpi,:
无法分配位图
2:在grDevices :: png(...,width = width,height = height,res = dpi,:
开启设备失败
以前我用ggsave保存过这个大小的png,任何想法为什么它不起作用?
可重复的例子:
library(car)
qplot(education,data = Vocab,geom = density,color = sex)+ facet_wrap(〜year)
注意:在Windows 7 64bit上使用R 2.12.1,此问题已消失,如果遇到此问题,请先尝试更新您的R版本。
b $ b在另一个问题中再次出现问题后,我重新输入了测试代码在我的新系统上,看看错误是否消失了,它是。
编辑:为什么底层代码可以工作是这样的,它使用的分辨率只有72 dpi,而不是300dpi,这是我认为的 ggsave()
中的标准。
so ggsave(tst.png,height = 9,width = 12,dpi = 72)
could做的伎俩。
但是如果它不能接受它,你真的必须有一个疯狂的阴谋。据我所知,问题与显卡有关(如来自Ripley教授的这则消息)。
如果解决方案是个问题,最好使用eps或pdf等矢量化格式。
编辑2:
显然,某处存在涉及某种内存泄漏的错误?给出以下代码:
library(car)
library(ggplot2)
qplot(education,data = Vocab,geom =density,color = sex)+ facet_wrap(〜year)
setwd(G:/ Temp)
i <-1
while(1){
tryCatch(ggsave(tst.png,height = 9 + i,width = 12 + i),error = function(e){print(i); stop(e);})
i< - 我+ 1
}
直到我达到9时,我得到你得到的错误。每次下一次尝试运行代码时,再次从 i = 1
开始,给出相同的错误。尝试使用 png()
和 dev.off()
会再次出现相同的错误。看起来好像有一部分内存被填满而没有被清空,有效地阻止了另一个PNG文件的保存。也对我来说 gc()
没有做任何事情。即使关闭R并再次打开也不起作用。
使用 I'm saving a faceted ggplot2 plot which works fine to save at a smaller size, but fails when I want to increase it. I've saved pngs of this size before with ggsave, any ideas why its not working? Reproducible example:
NOTE : Using R 2.12.1 on Windows 7 64bit, this problem has vanished. If you run into this problem, first try updating your R version. After the problem came up again in another question, I reran my test code on my new system to see if the bug was gone, and it is. EDIT: The trick why underlying code could work is the fact that it uses a resolution of only 72 dpi and not 300dpi as is the standard in so But you really must have a crazy plot if it can't take it. As far as I can guess, the problem is related to the graphics card (as derived from this message from prof. Ripley ). If resolution is a problem, you could better go to vectorized formats like eps or pdf. EDIT 2 : Apparently, there is a bug somewhere involving some kind of memory leak maybe? Give following code: This runs fine for me until i reaches about 9, then I get the error you get. Every next attempt at running the code, starting again with It is "solved" using 这篇关于ggsave png错误与较大的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ggsave(tst.pdf)$ c $ c>,但错误依然存在。我会向R团队汇报。
> ggsave("tst.png",height=6.75,width=9)
# works fine
> ggsave("tst.png",height=9,width=12)
Error in grDevices::png(..., width = width, height = height, res = dpi, :
unable to start device
In addition: Warning messages:
1: In grDevices::png(..., width = width, height = height, res = dpi, :
Unable to allocate bitmap
2: In grDevices::png(..., width = width, height = height, res = dpi, :
opening device failed
library(car)
qplot(education,data=Vocab,geom="density",colour=sex)+facet_wrap(~year)
ggsave()
I believe. ggsave("tst.png",height=9,width=12,dpi=72)
could do the trick.
library(car)
library(ggplot2)
qplot(education,data=Vocab,geom="density",colour=sex)+facet_wrap(~year)
setwd("G:/Temp")
i<-1
while(1){
tryCatch(ggsave("tst.png",height=9+i,width=12+i),error=function(e) {print(i);stop(e);})
i <- i+1
}
i=1
, gives the same error. Trying with png()
and dev.off()
gives again the same error. Seems like there is some part of a memory filling up and not being emptied, effectively preventing to get another png file saved. also for me gc()
didn't do a thing. Even closing R and reopening again didn't work.ggsave("tst.pdf")
, but the bug remains. I'd report to the R team.