[R] How to automate creation of plots (create series of plots)

Magdalena A. Tkacz magdalena.tkacz at gmail.com
Thu Apr 12 19:38:35 CEST 2012


Hi All.

I have problem with generating series of plots. In detail:

I have file of data which I insert into dataframe:
data<-read.table("file.txt", header=TRUE, sep=" ")

Data in this file are prepared in such a way, that the header of each
column has a value of one of examined parameter - something like that:
      X     Y           01.0    01.1   01.2   01.5  01.6   02.0
1  11.74 10.71      16      16      16      1        16    16
2  12.43 10.97      16      16      16      1        1      16
3  11.63 11.92      16      16       1       1        16    1

I need to generate a XY plot for each column (I need to observe
changes in context of parameter (header names) change).
Each column  has a few values and it is reflected in point's shape (pch).
I'm doing this using (example for fourth column):

plot(data$X~data$Y,main="Parameter, 01.1", pch=data$01.1)

In this way I have different point shape and value of parameter in
main plot label.


For the first few columns it is:
plot(data$X~data$Y,main="Parameter, 01.0", pch=data$Pr.01.0)

plot(data$X~data$Y,main="Parameter, 1.1", pch=data$Pr.01.1)

plot(data$X~data$Y,main="Parameter, 1.2", pch=data$Pr.01.2)
I use it together with par(mfrow=c(3,2)), so I have 6 plots at a time.

My question is:
How can I automate creation od plots?
The values in headers are not a series - they should be read from
header, because I can not prepare them in one or two "for" loops. (1.2
and next can be 1.5 next 2.0 next 2.7 -certain values are not
predictable)

The problem is that I have a lot of columns (now 57, sometimes - about
100, without initial filtering - more than 300).
Now I manually rewrite parameter value and copy line "plot(...)". It
is very laborious work, and I think it can be automated.

Does anyone has an idea how can I use data frame headers as parameters
in plot (legend and parameter of pch)?
I'm sure that it will be "for" loop - I know how many plots I need,
but what inside "for" (combining data frame header and plot
parameter)?

Regards

--
/|/| _ _ _/_ /_   _  /  / _ __
/   |(/(/(/(/((-/)(/ (  /((/( /_
     _/
Magdalena Tkacz



More information about the R-help mailing list