[R] re: help with lattice plot
Eve.McDonald-Madden@dse.vic.gov.au
Eve.McDonald-Madden at dse.vic.gov.au
Tue Jul 27 04:51:06 CEST 2004
Dear List,
I have been using R to create an xyplot using the panel function within
lattice libraries. This plot is based on the data supplied in R named
'Oats'. The graph represents oat yield by nitro level with an overlay of
each variety of oats for each nitro level.
I have three questions regarding this graph:
1) I cannot seem to specify the type of symbol used by the plot, even
though it is included in the code below, it will change when the code is
changed?
2) I have managed to include a legend on the graph using the key function;
however the labels of the legend do not seem to correspond to the right
coloured symbol as used in the plot itself for Variety. How can I get the
symbols and text in the legend to match that used in the graph itself?
3) Also, I am interested to know how I can manipulate the order in which
each graph (in this instance Nitro level) appears? For example, at the
moment the graphs do not appear in numerical order (based on the levels of
the factor nitro) can I reorder them so that they appear in the order I,
II, III,
IV, V, VI
?
The code I have used is included below:
##Data
library(nlme)
data(Oats)
##Factors
Oats$Block<-factor(Oats$Block)
Oats$Variety<-factor(Oats$Variety)
Oats$nitro<-factor(Oats$nitro)
attach(oats)
##Plot
library(lattice)
lset(col.whitebg())
xyplot(yield~nitro|Block, data=Oats,xlab="Nitrogen Level",ylab="Yield of
oats",subscripts=T, groups=Oats$Variety, as.table=T,
panel=function(x,y,groups,subscripts){
panel.superpose(x=x, y=y, groups=Oats$Variety,
subscripts=subscripts,pch=18)
panel.superpose(x=x, y=y, groups=Oats$Variety, subscripts=subscripts, type
="r")
}
,key = list(points = Rows(trellis.par.get("superpose.line"),c(1:2,3)),text
= list(lab = as.character(unique(Oats$Variety))),pch=18)
)
I would greatly appreciate anyone's time in assisting me with this request.
I look forward to your reply
Regards
Eve
Eve McDonald-Madden
Fauna Ecology
Arthur Rylah Institute for Environmental Research
Heidelberg, Victoria.Australia
Email: eve.mcdonald-madden at nre.vic.gov.au
More information about the R-help
mailing list