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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With