[R] Fwd: User defined panel functions in lattice
Duncan Mackay
mackay at northnet.com.au
Fri Apr 20 00:34:47 CEST 2012
Hi ilai
Thank you for your suggestions.
I do not know what happened yesterday I must have omitted a few
changes out in going from R to email
and apologies for the double posting - I had troubles sending it as
my ISP gave a message of not being connected for email but was for the web
I was trying to get panel.Locfit to work in a number of situations.
1. Conditioned by Farm (3 panels) with 2 sets of lines and points OK
2. Conditioned by Farm (1panel) with 3 sets of lines and points OK
3. What I want to be able to add in the above is extra lines with
different values of nn.
I think I will have to modify panel.Locfit so that it goes
through different values of nn in each of the panels and groups if I
want different colours for extra lines with different nn values
4 Produce an extra line for a fit for all the groups in 1/2+ panels.
As for 3 but I do not know how to group all the x and y's for
each of the panes using panel.groups
I need to do this and then scale up for a panel function to include
confidence bands
For the record making Farm and Padd factors. With 1 panel and groups
= Farm works with the extra line the same colour for its group
a similar situation for the three panels when conditioned by Farm and
groups = Pad
xyplot(y ~x, xx,
groups = Farm,
par.settings = list(strip.background = list(col = "transparent"),
superpose.line = list(col = c("black","grey"),
lwd = c(1,2,3),
lty = c(2,1,3)),
superpose.symbol = list(cex = c(0.8, 0.7,0.7),
col =
c("red","black","blue"),
pch = c(20,4,16))
),
auto.key=list(lines=T,points = T,rectangles=F),
panel = panel.superpose,
panel.groups=function(x,y, ...){
panel.xyplot(x,y,...)
panel.Locfit(x,y,...) # default 0.7
panel.Locfit(x,y,nn=0.9,...)
}
) ## xyplot
Regards
Duncan
At 02:12 20/04/2012, you wrote:
>On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay <mackay at northnet.com.au> wrote:
> > Hi
> >
> > xyplot(y ~x|Farm,xx,
> > groups = Padd,
> > panel = panel.superpose,
> > panel.groups=function(x,y, ...){
> > panel.Locfit(x,y,...)
> > panel.xyplot(x,y,...)
> > }
> > ) ## xyplot
> >
> > The above works nicely and also without par.setting giving
> lattice defaults.
> > The par.setting is handy for a lot of graphs that I do.
> >
> > But when I tried a 1 panel plot I get the error message.
> >
> > xyplot(y ~x,xx,
> > groups = Farm,
> > auto.key=TRUE,
> > panel = function(x,y, ...){
> >
> > panel.Locfit(x,y,...)
> > panel.xyplot(x,y,...)
> > }
> > )
> >
>
>These two plots are NOT THE SAME. Did you want the same as the first
>but with groups being Farm and Padd ignored ? in that case you (again)
>need a panel.groups:
>
> xyplot(y ~x,xx,
> groups = Farm,
> auto.key=TRUE,
> panel = panel.superpose,panel.groups=function(x,y,...){
> panel.Locfit(x,y,...)
> panel.xyplot(x,y,...)
> }
> )
>
>
> > If I want to plot another curve with different smoothing
> > but gives an error message without par.settings if i want to add
> > panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...)
> >
> > Error using packet 1
> > formal argument "Iwd" matched by multiple actual arguments
>
>It is all in the way you initially specified how to pass the arguments
>for panel.Locfit. This works without error:
>
> xyplot(y ~x,xx,
> groups = Farm,
> auto.key=TRUE,lwd=1:3,
> panel = panel.superpose,panel.groups=function(x,y,nn,...){
> panel.Locfit(x,y,nn=.9,...)
> panel.xyplot(x,y,...)
> }
> )
>
>
>HTH
>
>
>
> > I also need to plot a smoothed line for all groups trying groups,
> subscripts
> > and panel.groups as arguments without success
> >
> > Any solutions to solve the above will be gratefully received and faithfully
> > applied.
> >
> > Duncan
> >
> > sessionInfo()
> > R version 2.15.0 (2012-03-30)
> > Platform: i386-pc-mingw32/i386 (32-bit)
> >
> > locale:
> > [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
> > LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
> > LC_TIME=English_Australia.1252
> >
> > attached base packages:
> > [1] datasets utils stats graphics grDevices grid methods
> > base
> >
> > other attached packages:
> > [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2
> foreign_0.8-49
> > chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 RColorBrewer_1.0-5
> > [9] lattice_0.20-6
> >
> > loaded via a namespace (and not attached):
> > [1] tools_2.15.0
> >
> >
> >
> > Duncan Mackay
> > Department of Agronomy and Soil Science
> > University of New England
> > ARMIDALE NSW 2351
> > Email home: mackay at northnet.com.au
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list