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

Magdalena A. Tkacz magdalena.tkacz at gmail.com
Thu Apr 12 22:37:25 CEST 2012


Hi.
Yes, that was about scatterplot.

Your suggestion is what I really want.
Works excellent!!
Thank you very much.

Your question about the values and the headers...
I'm trying to develop new clustering algorithm.
I'm changing this algorithm's parameter and trying to "tune it up" in
dependency of parameter.
In my summary data file the headers of columns are the value of
examined parameter (1st row), all other rows in this column are
class/group numbers (I need different symbols for them)
All I need is to see how classes are created in dependency on
parameter - so it is possible that I just want different symbols.

Thank you again

Regards

Magdalena

2012/4/12 R. Michael Weylandt <michael.weylandt at gmail.com>:
> I'm not quite sure what you are asking -- when you say an XY plot I
> presume you mean a scatter plot of X against Y, but how do the values
> underneath the headers play in? Do you just want different symbols?
>
> With a little bit of data wrangling, I think this actually seems quite
> well suited to the ggplot2 paradigm, but here's one way to approach it
> in base graphics:
>
> for(i in 3:NCOL(dat)){
>    plot(dat$X, dat$Y, pch = dat[,i], main = paste("Parameter", names(dat)[i]))
> }
>
> Michael
>
>
>
> On Thu, Apr 12, 2012 at 1:38 PM, Magdalena A. Tkacz
> <magdalena.tkacz at gmail.com> wrote:
>> 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
>>
>> ______________________________________________
>> 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.



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



More information about the R-help mailing list