ggsave png错误与较大的大小 [英] ggsave png error with larger size

查看:947
本文介绍了ggsave png错误与较大的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ 

我保存了一个刻面的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并再次打开也不起作用。



使用 ggsave(tst.pdf),但错误依然存在。我会向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.

> 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

I've saved pngs of this size before with ggsave, any ideas why its not working?

Reproducible example:

library(car)
qplot(education,data=Vocab,geom="density",colour=sex)+facet_wrap(~year)

解决方案

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 ggsave() I believe.

so ggsave("tst.png",height=9,width=12,dpi=72) could do the trick.

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:

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
}

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 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.

It is "solved" using ggsave("tst.pdf"), but the bug remains. I'd report to the R team.

这篇关于ggsave png错误与较大的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆