I have an R script, which creates a plot and then saves it using ggsave. If I run each command in the R script one by one, in RGui, they all work and ggsave works too.
Similarly, if I submit each command at R prompt one by one, in the MS DOS command window, they all work and ggsave works too.
But If I do a >R CMD BATCH myscript.R, no file is saved by ggsave. I have tried to save a .png file, a .jpg file, or a .pdf file. In all 3 cases, the file did not get created.
However a RPlots.pdf does get created automatically. Now I can always convert this Rplots.pdf to a .png file, in my C# asp.net code, but I do not want to lose any quality aka resolution and waste time either. I am not sure if I will lose any quality aka resolution during such conversion. It will be better to generate the correct file upfront.
here is the code from the R script
library(stats)
library(ggplot2)
getwd()
setwd("C:\\Users\\..................")
mydatadata <- read.csv(file = "boxplot_test_data.csv", header = TRUE, sep = ",")
ggplot(mydata, aes(y=Y, x=X, fill=fillFactor)) +
geom_boxplot(outlier.color=NA) + geom_point(aes(size=AXI, shape=FA), color="gold", position=position_jitter(width=0.1, height=0))
ggsave("myggplot2.png")
# I tried this approach too. No success either.
#figure1<-last_plot()
# I tried this approach too. No success either.
#ggsave(figure1, file="myggplot2.png")