Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : Unable to start png() device

Tags:

r

I am using Windows. When trying to plot a graph on png device, it fails with the error.

My code:

png("C:\\plot1.png", width = 480, height = 480, units = "px", bg = "white")

par(mar= c(4, 4, 2, 1))

hist(pwrcon$Global_active_power,col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)")

dev.off()

Error:

Error in png("C:\\plot1.png", width = 480, height = 480, units = "px",  : 
  unable to start png() device
In addition: Warning messages:
1: In png("C:\\plot1.png", width = 480, height = 480, units = "px",  :
  unable to open file 'C:\plot1.png' for writing
2: In png("C:\\plot1.png", width = 480, height = 480, units = "px",  :
  opening device failed

Can anyone help me in getting this resolved?

Thanks in advance

like image 306
NSN Avatar asked Jul 15 '17 01:07

NSN


2 Answers

I cannot explain why, but I once found that when the folder path in which my RStudio project was saved was a very long character string, the png device would fail. When I shortened the folder path it worked.

like image 116
Nayef Avatar answered Oct 12 '22 23:10

Nayef


I had the same issue while working in an r-markdown document.

The issue in my case had something to do with viewing the Chunk Output Inline. When I switched to viewing the Chunk Output in Console, it worked just fine.

like image 35
Adrienne B Avatar answered Oct 12 '22 23:10

Adrienne B