Specifying plot file name in the rscript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Specifying plot file name in the rscript

Mahmood Naderan-Tahan
Hi

I use the following R script to plot two graphs.


library(FactoMineR)
mydata <- read.csv('test.csv', header=T,row.names=1)
res.pca = PCA(mydata, quali.sup=5, graph=F)
plot(res.pca, choix="var", axes=c(1,2))
dev.new()
plot(res.pca, choix="ind", axes=c(1,2))

After running "Rscript my.r", I see two pdf files Rplots.pdf and Rplots1.pdf.
I would like to specify file names in the script as well. How can I do that?


Regards,
Mahmood

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying plot file name in the rscript

Ben Tupper-2
Hi,

When you call plot() it will draw to the default device - in your case
the pdf() device. When the default device results in a file, R selects
a filename for you unless you tell it otherwise.  You can specify the
filename by explicitly calling pdf() first.

pdf("var_plot.pdf")
plot(res.pca, choix="var", axes=c(1,2))
dev.off()

pdf("ind_plot.pdf")
plot(res.pca, choix="ind", axes=c(1,2))
dev.off()

See ?device for a listing of available devices.

Ben


On Tue, Mar 9, 2021 at 7:11 AM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi
>
> I use the following R script to plot two graphs.
>
>
> library(FactoMineR)
> mydata <- read.csv('test.csv', header=T,row.names=1)
> res.pca = PCA(mydata, quali.sup=5, graph=F)
> plot(res.pca, choix="var", axes=c(1,2))
> dev.new()
> plot(res.pca, choix="ind", axes=c(1,2))
>
> After running "Rscript my.r", I see two pdf files Rplots.pdf and Rplots1.pdf.
> I would like to specify file names in the script as well. How can I do that?
>
>
> Regards,
> Mahmood
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.



--
Ben Tupper
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying plot file name in the rscript

Mahmood Naderan-Tahan
Right. Thank you very much.


Regards,
Mahmood

________________________________
From: Ben Tupper <[hidden email]>
Sent: Tuesday, March 9, 2021 2:58:17 PM
To: Mahmood Naderan-Tahan
Cc: [hidden email]
Subject: Re: [R] Specifying plot file name in the rscript

Hi,

When you call plot() it will draw to the default device - in your case
the pdf() device. When the default device results in a file, R selects
a filename for you unless you tell it otherwise.  You can specify the
filename by explicitly calling pdf() first.

pdf("var_plot.pdf")
plot(res.pca, choix="var", axes=c(1,2))
dev.off()

pdf("ind_plot.pdf")
plot(res.pca, choix="ind", axes=c(1,2))
dev.off()

See ?device for a listing of available devices.

Ben


On Tue, Mar 9, 2021 at 7:11 AM Mahmood Naderan-Tahan
<[hidden email]> wrote:

>
> Hi
>
> I use the following R script to plot two graphs.
>
>
> library(FactoMineR)
> mydata <- read.csv('test.csv', header=T,row.names=1)
> res.pca = PCA(mydata, quali.sup=5, graph=F)
> plot(res.pca, choix="var", axes=c(1,2))
> dev.new()
> plot(res.pca, choix="ind", axes=c(1,2))
>
> After running "Rscript my.r", I see two pdf files Rplots.pdf and Rplots1.pdf.
> I would like to specify file names in the script as well. How can I do that?
>
>
> Regards,
> Mahmood
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.



--
Ben Tupper
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.