[R] combination xyplot and barchart?

Erin Berryman berr0179 at umn.edu
Wed Nov 16 00:43:13 CET 2005


Dear R community,

I am having trouble determining how to create the graph I want 
utilizing my relatively limited knowledge of R. So far I have been 
using the lattice library to create most of what I need.
The dataset (enviro) consists of 2 variables (Temp and Precip) for each 
Day of a 2-yr period (Year). I wish to display Temp and Precip along 
the y axis plotted by Day on the x axis to allow comparison (one year's 
data in each of 2 panels stacked on top of each other) between the 
years. Essentially what I want it to look like is an xyplot (Temp ~ Day 
| Year, type='l') superimposed onto a barchart(Precip ~ Day | Year, 
horizontal=F), with scales adjusted so one can see detail in both 
variables.
The closest I have come to what I need is by the following code :

library(lattice)
barchart(Precip + Temp ~ Day | Year, data=enviro, layout=c(1,2), 
horizontal=F, origin=0, 
panel=function(x,y,subscripts,...){panel.xyplot(x=enviro$Day, 
y=enviro$Temp, type='l',subscripts=subscripts, ...); 
panel.barchart(x=enviro$Day, y=enviro$Precip, subscripts=subscripts, 
...)})

Two panels are produced; however, both years' data are plotted in each 
panel (panels look identical). And I get this error:

Error in grid.Call.graphics("L_rect", x$x, x$y, x$width, x$height, 
resolveHJust(x$just,  :
	invalid line type

 From the documentation or the help archives, I cannot understand how to:
1) indicate a conditioning variable (Year) for panel.barchart and 
panel.xyplot
2) have 2 y axes with different scales in one panel

Is this even possible to do using lattice? Any insight is greatly 
appreciated.

Thanks,

Erin


Erin M. Berryman
Graduate Research Assistant
Department of Soil, Water, and Climate
University of Minnesota




More information about the R-help mailing list