[R] Plot a matrix recursively

Roland Rau roland.rproject at gmail.com
Wed Dec 1 15:00:27 CET 2010


On 12/01/2010 02:43 PM, alcesgabbo wrote:
>
> I plot the first column with the following function:
> plot(m[,1],type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1,
> max(m[,1:length(colnames(m))])+1))
>
> for the other columns I use there functions:
>
> lines(m[,2],type=\"o\")
>
> lines(m[,3],type=\"o\")
>
> ok, it works.
>
> But is there a way to do this prodcedures recursively??
>
> for example:
>
> for each columns {
>   lines(m[,column],type=\"o\")
> }
>
> I try with :
>
> lines(m[,2:length(colnames(m))],type=\"o\")

Is there a special need to do it recursively?

Would the following not do the trick, too?

m <- matrix(c(1,6,3,2,5,4,3,6,3,4,5,4), byrow=TRUE, ncol=3)
matplot(m, type="o", xaxt="n",ylim=c(min(m[,1:length(colnames(m))])-1,
                                 max(m[,1:length(colnames(m))])+1),
         lty=1, col="black")

Or simply:
matplot(m, type="o", xaxt="n", lty=1, col="black")

Hope this helps,
Roland



More information about the R-help mailing list