[R] lattice barchart

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Nov 18 12:31:12 CET 2009


On Tue, Nov 17, 2009 at 3:31 PM, Wilberforce
<will.parry at matrixknowledge.com> wrote:
>
> I have a data frame with two factors and want to create panel barcharts with
> one factor defining the panels and the other the vertical categories by
> which I can count the rows of data in each combination of factors. How do I
> do this?
>
> I have been trying to use barchart(~factor1|factor2) but it does not give
> the panels as I want them.
>
> The data looks like this:
>
> Factor1    Factor2
> A             y
> B             y
> A             x
> B             y
> C             x
> etc...

You need to tabulate your data first; barchart() won't do that for you.

Start with

barchart(xtabs(~Factor1 + Factor2, your.data))

and try using

as.data.frame(xtabs(~Factor1 + Factor2, your.data))

as the data= argument for more flexibility.

-Deepayan




More information about the R-help mailing list