Skip to content

Lattice bwplot(): Conditioning on one factor

7 messages · Rich Shepard, David Winsemius, Bert Gunter

#
I'm not able to create the proper syntax to specify a lattice bwplot() for
only one of two conditioning factors.

   The syntax that produces a box plot of each of the two conditioning
factors is:

bwplot(quant ~ param | era, data=mg.d, main='Dissolved Magnesium', ylab='Concentration (mg/L)')

   What I've tried unsuccessfully are:

bwplot(quant ~ param | factor(era=='Pre-mining'), data=mg.d,
main='Magnesium', ylab='Concentration (mg/L))

bwplot(quant ~ param | era, data=mg.d, main='Magnesium', ylab='Concentration
(mg/L)', subset=era('Pre-mining'))

plus slight variations of the above. None work.

   Please point me to what I've missed in specifying only one of two
conditioning factors for the plot.

Rich
#
On Sep 28, 2012, at 7:49 AM, Rich Shepard wrote:

            
Wouldn't that involve specifying the 'subset' parameter (if bwplot accepts a subset argument) or using the 'subset' function to pass the desired rows to the data argument if it doesn't?
#
A small reproducible example, as requested bythe posting guide, would
have been very helpful here (if you provide one, use ?dput to provide
the data). You have also not told us what you mean by "unsuccessful,"
so we are left to guess what sort of problems you experienced.  "None
work" is completely useless to help diagnose the problem. This means
we waste time going back and forth trying to elucidate what you mean.
Please consider these things if/when you post in future.

In any case, my guess is that param is numeric and it should be a
factor, so, e.g.

 bwplot(quant ~ factor(param) | era, data=mg.d, main='Dissolved
Magnesium', ylab='Concentration (mg/L)')

might be what you want. But of course, it may be completely wrong.

Cheers,
Bert
On Fri, Sep 28, 2012 at 9:25 AM, David Winsemius <dwinsemius at comcast.net> wrote:

  
    
#
On Fri, 28 Sep 2012, David Winsemius wrote:

            
David,

   That's what I tried:
Perhaps I didn't write it correctly.

Thanks,

Rich
#
On Sep 28, 2012, at 9:56 AM, Rich Shepard wrote:

            
Sigh. If I were testing that strategy (which I did not try because you were too busy to have included a working example)  I would have written it:

bwplot(quant ~ param , data=mg.d, main='Magnesium', ylab='Concentration
(mg/L)', subset= era=='Pre-mining' )

That passes a logical vector which will "work" only if bwplot created an local environment where column names of the 'data' argument have been added to the local namespce. I do not know if that is true. I just looked at the bwplot help page and do not see a subset argument documented there.

The other suggestion which it seems you were also to busy too have tried was:

bwplot(quant ~ param ,  main='Magnesium', ylab='Concentration
(mg/L)', data = subset( mg.dsubset,  era=='Pre-mining' ) )

Wrapping a column name around a factor level with parentheses (which R takes to mean there is a function named 'era' to be applied)  and expecting R to understand the you want a subset seems doomed to failure.

It makes no sense to me to condition on a factor that you know for certainty has only one level in the data being offered.
--

David Winsemius, MD
Alameda, CA, USA
#
On Fri, 28 Sep 2012, David Winsemius wrote:

            
David, Don:

   Thank you. I tried subset= and era== separately, not together.

   Now I know.

Much appreciated,

Rich
#
Yes. Now I understand what was wanted.

1. the subset argument is certainly documented on the Help page:

subset 	

An expression that evaluates to a logical or integer indexing vector.
Like groups, it is evaluated in data. Only the resulting rows of data
are used for the plot. If subscripts is TRUE, the subscripts provided
to the panel function will be indices referring to the rows of data
prior to the subsetting. Whether levels of factors in the data frame
that are unused after the subsetting will be dropped depends on the
drop.unused.levels argument.

Had the OP read this carefully, he would have presumably recognized
the errors in his specification.

2. Here is a small reproducible example to show how it should be done
(probably unnecessary now):
## The logical condition is parenthesized only for clarity

Cheers,
Bert



On Fri, Sep 28, 2012 at 10:10 AM, David Winsemius
<dwinsemius at comcast.net> wrote: