[R] lattice barchart() with two variables
Rich Shepard
r@hep@rd @end|ng |rom @pp|-eco@y@@com
Wed Aug 22 20:18:34 CEST 2018
On Wed, 22 Aug 2018, Bert Gunter wrote:
> (I know that you said your post may already be "out of date", but ...)
Bert,
Still reading ?xyplot/?barchart.
> But ?barchart says:
> "Formally, if groups is specified, then groups along with subscripts is
> passed to the panel function, ..."
>
> which, as I already told you, means you should consult ?panel.barchart . In
> particular, the example therein tells you exactly how the "groups" argument
> should be specified and how it works (you can change colors via the "col"
> argument, of course). Note, in particular, that "groups" must be your
> grouping variable, which means, in particular, that you need to reformat
> your data frame in what is currently referred to as "tidy" format (aka
> "long" format as opposed to "wide") -- one variable per column, one
> observation per row. That is:
>
> Year Value Summary.Type
> 1991 91.24 "Med"
> 1991 92.89 "Max"
> ... etc.
I saw this in examples and missed its application to my data. You've
cleared my confusion and now I _do_ understand the need for a separate
grouping column and reshaping to a long format. Thanks for explaining so
effectively.
> As an aside, this is a good example of why you should adhere to this
> format for data analysis in R.
I've done this with all my other data sets and have no excuse for not
doing so with this one. Mea culpa!
Best regards,
Rich
More information about the R-help
mailing list