Re: [R] Plotting matrix rows with lattice graphics?

From: Ron Bonner <arbi56_at_gmail.com>
Date: Tue, 25 Mar 2008 13:04:09 -0400

Thanks Henrique - that didn't exactly solve my problem but gave me enough to do so!

In your solution each row is plotted as a vertical row of points at the value of 'ind' while I wanted to plot the values against the column numbers, i.e. 1 to 5.

The solution was to create a vector of column numbers, replicate it and plot against it, still using 'ind' as the conditioning variable:

> m <- matrix(1:20, c(4,5))

> m

     [,1] [,2] [,3] [,4] [,5]

[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20

> pr <- rep(c(1,2,3,4,5), 4)

> d <- cbind(pr=pr, stack(split(m, 1:4)))

> xyplot(pr ~ values|ind, data=d)

Thanks again for the help

Ron

On Tue, Mar 25, 2008 at 7:42 AM, Henrique Dallazuanna <wwwhsd_at_gmail.com> wrote:

> Maybe:
>
> xyplot(values ~ ind|ind, data = stack(split(m, 1:4)))
>
> On 24/03/2008, Ron Bonner <arbi56_at_gmail.com> wrote:
> > Sorry if this is an FAQ, but I haven't found the answer (yet)...
> >
> > I'm trying to plot each row of a simple numeric matrix in a separate
> > panel using the layout features of lattice, but can't make it work -
> > help would be appreciated!
> >
> > Example:
> >
> > > m <- matrix(seq(1:20), nrow=4)
> >
> > > m
> > [,1] [,2] [,3] [,4] [,5]
> > [1,] 1 5 9 13 17
> > [2,] 2 6 10 14 18
> > [3,] 3 7 11 15 19
> > [4,] 4 8 12 16 20
> >
> > The following will plot one row in one box:
> >
> > > xyplot(m[1,] ~ seq(1:5))
> >
> > but this gives all rows in the same box:
> >
> > > xyplot(m ~ seq(1:5))
> >
> > Since there are no factors, how can I set conditioning variable to get
> > what I want, or is there a better way to do this?
> >
> > Thanks in advance
> >
> > Ron
> >
> > Ron Bonner
> > arbi56_at_gmail.com
> > skype: rbonners
> >
> >
> >
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

        [[alternative HTML version deleted]]



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. Received on Tue 25 Mar 2008 - 18:21:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 25 Mar 2008 - 18:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive