Call graph () from R script and get graph in output file?

I created an R script that reads certain data from a file, calls a method summary(), and then a method plot().

But when I try to run the R script, where the commands below are written, in the output file I get a summary, but not a graph.

When I run the following instructions in R manually, everything works fine, and I get both a summary and a graph.

Is there any way to get the graph in the output file?

m0<-read.csv(file="Myfile", head=FALSE, sep",")
var_m0<-c(m0$ V3)
summary(var_m0)
plot(var_m0)

Thank!

+5
source share
1 answer

You need to tell R what type of output you want, and where you want it to go. Take a look at ?pngfor a fairly complete list. And do not forget dev.off()after your call plot()!

m0 <- read.csv(file="Myfile", head=FALSE, sep",")
var_m0 <- c(m0$ V3)
summary(var_m0)

png('plot.png')
plot(var_m0)
dev.off()

, , knitr sweave.

+8

All Articles