[R] Plot a series of plots without using a loop

Rui Barradas ruipbarradas at sapo.pt
Tue Jul 30 13:35:33 CEST 2013


Hello,

Maybe the following does it.

op <- par(mfrow=c(2, 3))

for(i in 1:6){
	plot(somdata.xyf,
	     type="property",
	     property=somdata.xyf$codes$X[, i],
	     main=colnames(somdata.xyf$codes$X)[i])
}

par(op)


Hope this helps,

Rui Barradas

Em 30-07-2013 10:33, Ben Harrison escreveu:
> I have an xyf object from the kohonen package, and wish to plot a
> lattice or grid or multiplot of a set of attributes of this object.
>
> I've included the structure of the object below for reference, and
> here is the set of plots I wish to produce, given in long-hand. I
> don't know enough R to generalise this set of commands, can you help?
> I am looking for a single command if possible.
>
> op <- par(mfrow=c(2, 3))  # 6 plots in this case
> plot(somdata.xyf,
>       type="property",
>       property=somdata.xyf$codes$X[, 1],
>       main=colnames(somdata.xyf$codes$X)[1])
>
> plot(somdata.xyf,
>       type="property",
>       property=somdata.xyf$codes$X[, 2],
>       main=colnames(somdata.xyf$codes$X)[2])
>
> ... etc...
>
> plot(somdata.xyf,
>       type="property",
>       property=somdata.xyf$codes$X[, 6],
>       main=colnames(somdata.xyf$codes$X)[6])
>
> par(op)
>
> The "codes" list of the somdata.xyf object contains a further list "X"
> containing the items I wish to plot. So the properties are
> somdata.xyf$codes$X[, 1:6].
>
> Here are some of the details (snipped for clarity):
>
>> str(somdata.xyf)
> List of 12
>   $ data        : num [1:68, 1:6] -0.7509 -0.057 -1.5547 -0.4019 -0.0192 ...
> ... <snip>
>   $ codes       :List of 2
>    ..$ X: num [1:25, 1:6] -2.006 -0.817 -0.249 0.131 0.476 ...
>    .. ..- attr(*, "dimnames")=List of 2
>    .. .. ..$ : NULL
>    .. .. ..$ : chr [1:6] "MEAS_TC" "SP" "LN" "SN" ...
>    ..$ Y: num [1:25, 1] -2.006 -0.817 -0.249 0.131 0.476 ...
>   $ changes     : num [1:500, 1:2] 0.1058 0.0954 0.1197 0.1085 0.1279 ...
> ... snip
>
>
>> head(somdata.xyf$codes$X)
>          MEAS_TC         SP         LN         SN         GR        NEUT
> [1,] -2.0058516 -0.3207971 -0.2886428 -0.2645986 -0.3874740 -0.41095949
> [2,] -0.8167927  0.1898585 -0.4094999 -0.3778524  0.3163603  0.05596098
> [3,] -0.2492923 -0.8087226  0.4889264  0.2041352 -0.2634253 -0.27536594
> [4,]  0.1309919  0.1330020  2.0283477  2.4009782 -0.5614304  0.82821634
> [5,]  0.4764463 -0.1288688 -0.3767898 -0.3946008 -0.8674591 -0.19527494
> [6,] -1.5912249  0.5690732 -0.2411219 -0.1630187 -0.4678983 -0.80916499
>
> Ben
> University of Melbourne
>
> ______________________________________________
> 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