Re: [R] re: help with lattice plot

2004-07-26 Thread Deepayan Sarkar
On Monday 26 July 2004 21:51, [EMAIL PROTECTED] wrote:
> 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?

You are doing several things wrong. There's more than one way to fix it. 
For example, the approach you have taken may be modified to give (after 
the lset(col.whitebg()) call in your example):


lset(list(superpose.symbol = list(pch = 18)))
xyplot(yield ~ nitro | Block,
   data = Oats,
   xlab = "Nitrogen Level",
   ylab = "Yield of oats",
   groups = Variety,
   as.table = T,
   panel = function(x, y, groups, subscripts) {
   panel.superpose(x = x, y = y, groups = groups,
   subscripts = subscripts)
   panel.superpose(x = x, y = y, groups = groups,
   subscripts = subscripts,
   type ="r")
   },
   key =
   list(points = Rows(trellis.par.get("superpose.symbol"), 1:3 ),
text = list(lab = levels(Oats$Variety

A line by line comparison with your code should indicate the 
differences.

But since you are using some lattice-specific features (not available in 
S-PLUS) anyway, I would take it a bit further and simplify this to 
(again, after the lset(col.whitebg()) call in your example):

xyplot(yield ~ nitro | Block,
   data = Oats,
   xlab = "Nitrogen Level",
   ylab = "Yield of oats",
   groups = Variety,
   as.table = TRUE, 
   type = c("p", "r"),
   par.settings = list(superpose.symbol = list(pch = 18)),
   auto.key = TRUE)


> 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? 

Wherever there's the need for 'ordering' a factor, the order is 
determined by its levels - given by the levels() function. In this 
case, the order would be given by levels(Oats$Variety), and not 
as.character(unique(Oats$Variety)) which you were using for some 
reason. This fact is relevant to your next question as well.

> 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 ?

Surely you mean Block and not nitro?

It behaves in this way because that's the order given by 
levels(Oats$Block) (the reason should be apparent after 
reading ?groupedData from nlme). You can choose your own order when 
using the factor function (your current use doesn't do anything, by the 
way):

Oats$Block <-
factor(Oats$Block,
   levels = c("I",  "II",   "III", "IV",  "V",  "VI"))


Hope that helps,

Deepayan

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] re: help with lattice plot

2004-07-26 Thread Eve . McDonald-Madden
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:  [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html