[R] scripting qqplot and qqnorm

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Jul 27 19:55:00 CEST 2011



On 25.07.2011 07:11, Vihan Pandey wrote:
> Hi all,
>
> I am an R newbie, and I have a question about scripting. I have the
> following lines which I want to put int\
> o a script which I can call from the shell of a Mac/Linux machine :
>
> myrns<- read.csv(file="/Users/vihan/test.csv",sep="",header=FALSE)
> qqnorm(myrns)
> qqline(myrns)
>
> This works fine on an interactive R session.
>
> However, as I understand the basic framework of an R script for
> executing on the shell to get a pdf output it is something like :
>
> #!/usr/bin/Rscript
>
> … list inputs…
>
> pdf("plotexample.pdf", width=7, height=9)
>
> plot(...)
>
> dev.off()
>
> print(paste("Plot was saved in:", getwd()))
>
>
> therefore, I do :
>
>
> #!/usr/bin/Rscript
>
> myrns<- read.csv(file="/Users/vihan/test.csv",sep="",header=FALSE)

The call to pdf() is missing.


> qqnorm(myrns)
>
> dev.off()
>
> print(paste("Plot was saved in:", getwd()))
>
> but it does not work, the pdf generated is something my pdf viewer
> cannot understand, plot(qqnorm(myrns)) and plot(qqline(myrns)) don't

This suggests you forgot the dev.off() part or that was not executed at 
least, please see the R output and watch out for error messages.


> work either.
>
> Any ideas on what I'm doing wrong?
>
> Moreover, would it be possible to have both qqline(myrns) and
> qqnorm(myrns) on the same pdf?


Just call then after pdf() and before dev.off(), a 2 page will be in the 
resulting pdf file.

Uwe Ligges


>
> Cheers!
>
> - vihan
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list