I have created an R script that reads certain data from a file, calls the summary()
method and then the plot()
method.
But when I try to run the R script where the commands below are written, in the output file I get the summary, but not the graph.
When I run the following instructions in R manually, everything works perfectly, and I get both the summary and the graph.
Is there a 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)
Thanks!
You need to tell R what kind of output you want and where you want it to go. Take a look at ?png
for a fairly comprehensive list. And don't forget dev.off()
after your plot()
call!
m0 <- read.csv(file="Myfile", head=FALSE, sep",")
var_m0 <- c(m0$ V3)
summary(var_m0)
png('plot.png')
plot(var_m0)
dev.off()
If you specifically want the graph in the same output file as the rest of the code, you can look at knitr
and sweave
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With