I was trying to plot a series of scatterplots with different sets of variables. In doing so, I use "paste" to combine two (or more) variable names as
plot.name <- paste(paste("var1.name", "var2.name",..., sep="_"), "plot.png", sep=" ")
Then I use this name in "ggsave" as
ggsave(plot.name, width=7.5, height=5, units="in", dpi=300)
Each time I tried I get
Error in grDevices::png(..., res = dpi, units = "in") : unable to start png() device
In addition: Warning messages:
1: In grDevices::png(..., res = dpi, units = "in") : unable to open file 'plot.name'
2: In grDevices::png(..., res = dpi, units = "in") : opening device failed
This only happens when I use a plot name created with "paste" containing 2 or more variable names but it does not happen if I use just "plot.png" or a single thread of character ("xxx xxx xxx xxx.png"). This happens with all types of devices (jpg, etc.). Does anyone have any idea why a simple name works but not a name created by "paste" does not to save images? This was never the issue before but it started happening when I tried to use Rstudio. I normally write all codes in Tinn-R then export them to R.
The followings are more details.
Names of 4 variables are;
x.var.actual.name.list <-
c("Elev.Nov.Prev.2.mo", "Sal.Fall", "ArtBio.Sep.Prev", "min.temp.Sep.Prev.2.mo")
An input dataframe is:
df.in <- combined.df[,c(y.var, x.var.actual.name.list)]
Total Elev.Nov.Prev.2.mo Sal.Fall ArtBio.Sep.Prev min.temp.Sep.Prev.2.mo
10.158711 6381.35 83.05407 17.143527 48.27
10.684462 6381.00 83.64119 22.075855 49.38
10.849221 6380.30 84.70405 26.175721 46.06
10.021848 6381.55 82.23643 20.024815 47.19
10.019090 6384.15 77.78226 17.459871 47.13
10.171566 6382.55 80.97417 21.180415 49.33
...
For instance I use "ggcorr" from GGally package to plot correlation matrix;
require(GGally)
cor.scatter.png.file <- paste(paste(x.var.actual.name.list, collapse=" "),
"correlation scatter plot matrix.png", sep=" ")
cor.mat.plot <- ggcorr(df.in,2, palette = "RdYlGn", name = "r",label = T,
label_color = "black", label_round = 2)
ggsave(cor.scatter.png.file, width=7.5, height=5, units="in")
Above scrips result in an error;
Error in grDevices::png(..., res = dpi, units = "in") :
unable to start png() device
In addition: Warning messages:
1: In grDevices::png(..., res = dpi, units = "in") :
unable to open file 'Elev.Nov.Prev.2.mo Sal.Fall ArtBio.Sep.Prev
min.temp.Sep.Prev.2.mo correlation scatter plot matrix.png' for writing
2: In grDevices::png(..., res = dpi, units = "in") : opening device failed
But if I do the following (not using a pasted part of the name) it works.
ggsave("correlation scatter plot matrix.png", width=7.5, height=5, units="in")
The first script with a pasted name worked before, but stopped working after I tried to run the same script in Rstudio. Now anytime I use pasted names R returns the error message. I have uninstalled Rstudio and R and reinstalled R but the same issue persists. I appreciate any suggestions to fix this problem.