[R] Syntax Help for xyplot()

Daniel Nordlund djnordlund at frontier.com
Tue Oct 25 00:04:12 CEST 2011



> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Rich Shepard
> Sent: Monday, October 24, 2011 2:17 PM
> To: r-help at r-project.org
> Subject: Re: [R] Syntax Help for xyplot()
> 
> On Mon, 24 Oct 2011, Rich Shepard wrote:
> 
> >  Perhaps because it's Monday I'm not successfully writing the xyplot()
> > command to show the quant, for example, for TDS by site. What I need to
> do
> > is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
> 
>    I should have provided some of the attempts:
> 
> xyplot(quant ~ TDS | site, data = burns.tds.anal)
> Error in eval(expr, envir, enclos) : object 'TDS' not found
> 
> xyplot(quant ~ 'TDS' | site, data = burns.tds.anal)
> Warning messages:
> 1: In order(as.numeric(x)) : NAs introduced by coercion
> 2: In diff(as.numeric(x[ord])) : NAs introduced by coercion
> 3: In function (x, y, type = "p", groups = NULL, pch = if
> (is.null(groups))
> plot.symbol$pch else superpose.symbol$pch,  :
>    NAs introduced by coercion
> 
> This produces a plot with no data in each panel.
> 
> And I cannot see how to specify, for example, 'TDS' x 'Cond' because
> 
> xyplot('TDS'$quant ~ 'Cond'$quant | site, data = burns.tds.anal)
> Error in "TDS"$quant : $ operator is invalid for atomic vectors
> 
> and
> 
> xyplot('TDS'[quant] ~ 'Cond'[quant] | site, data = burns.tds.anal)
> There were 25 warnings (use warnings() to see them)
> 
> produces the panels without data in them.
> 
> Rich


Rich,

you need to reorganize your data so that you have a single record (i.e. row) for each site/sampdate combination with the quant value for each of your params save in a column named by the param value (I don't remember all the param names so I used pn).  For example your first two lines should be collapsed into a single line, e.g.

site sampdate     TDS Cond SO4 p4 p5 p6 p7
BC-0.5 1996-06-02 530 NA   194 NA NA NA NA

if you have other lines for site/sampdate

 BC-0.5 / 1996-06-02

then you would use the quant values to fill in for Cond and the other paramenters.  Then your xyplot code should work.  Someone else will need to show you how to do that manipulation.

Dan

Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list