I am trying to save a plot in png format. I am using the following code:
p <- ggplot(mtcars)+
geom_point(aes(x = hp, y = mpg))
png(filename = 'filename.png')
p
dev.off()
However, when I run without the file extension, it works:
p <- ggplot(mtcars)+
geom_point(aes(x = hp, y = mpg))
png(filename = 'filename')
p
dev.off()
The following error is raised:
Error in png(filename = "filename.png") :
não é possível iniciar dispositivo png()
In addition: Warning messages:
1: In png(filename = "filename.png") :
unable to open file 'filename.png' for writing
2: In png(filename = "filename.png") : opening device failed
The error is independent if I use png()
, jpeg()
or ggsave()
functions.
UPDATE:
- I already tried to clear my workspace, restarted the computer, and tried different folders with different access scopes. It only works if I don't use the *.png, *.jpeg or *.pdf extensions.
- It works for *.svg extensions.
- If I try to rename the file to add the .png extension, it does not work due to "access denied". But if I rename to add .svg extension, it works and converts the file to .svg.
Thanks all in advance :)