[R] lattice barchart() with two variables

Rich Shepard r@hep@rd @ending from @ppl-eco@y@@com
Wed Aug 22 17:02:13 CEST 2018

   I've not before created bar charts, only scatter plots and box plots.
Checking in Deepayan's book, searching the web, and looking at ?barchart has
not shown me the how to get the results I need.

   The dataframe looks like this:
> head(stage_heights)
   Year   Med   Max
1 1989 91.17 93.32
2 1990 91.22 93.43
3 1991 91.24 92.89
4 1993 91.14 93.02
5 1994 93.92 95.74
6 1995 94.34 96.85

   I want to show Med and Max heights for each Year with each bar having a
different color (or pattern) and a single x-axis year label.

   Trying to follow the example in ?barchart for a single variable produced this:

> barchart('Year' ~ 'Med', data=stage_height, panel=lattice.getOption('panel.barchart'), default.prepanel=lattice.getOption('prepanel.default.barchart'),box.ratio=2)
Error in eval(substitute(groups), data, environment(formula)) :
   invalid 'envir' argument of type 'closure'
and no plot was displayed.

   I must be missing the obvious and want a pointer to descriptions that
teach me how to produce bar charts.


More information about the R-help mailing list