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
filename
that we try to write the png. The folder we plan to use should be created in advance (using e.g.if(!dir.exist(folder_name) dir.create(folder_name)
). – Yang Liu