Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in grDevices::png

Tags:

r

quick.hist<-ggplot(ufo.us, aes(X=DateOccured))+geom_histogram()+scale_x_date()
ggsave(plot=quick.hist,filename= "../images/hist.png",height=6, width=8)

file format is simple:

it contains 2 dates,city,state,duration

I am getting error during plot:that is during ggsave()

Error in grDevices::png(..., width = width, height = height, res = dpi,  
  unable to start png() device

In addition: Warning messages:

 In grDevices::png(..., width = width, height = height, res = dpi,  
  unable to open file '../images/hist.png' for writing

 In grDevices::png(..., width = width, height = height, res = dpi,  
  opening device failed

I am very new to R and getting error. I have just started copying the book code for histogram chart, first chapter from book machine learning hacker perspective.

like image 359
user3589052 Avatar asked Apr 30 '14 12:04

user3589052


2 Answers

I had the same problem recently. It occurs when compiling R from source without having the appropriate libraries installed. So R does not know how to talk to the png device at all.

In order to fix this problem just install the following packages (e.g. using Ubuntu16.04)

sudo apt install libcairo2-dev libjpeg9-dev

and run the ./configure again.

If those libraries were sufficient both PNG and cairo should be listed as Additional capabilities at the end of the configuration. So if none of them shows up using

cat config.log | grep skipped

you are good to go.

like image 194
theGreatWhiteShark Avatar answered Sep 18 '22 19:09

theGreatWhiteShark


I had the same issue. In my case, my working directory (check getwd) was not the right one so the filepath didn't make sense.

like image 37
user3507584 Avatar answered Sep 19 '22 19:09

user3507584