Re: [R] Lattice graphics adding abline line (1:1 line) ???

2012-08-28 Thread PIKAL Petr
Hi


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of iwaite
 Sent: Tuesday, August 28, 2012 12:49 AM
 To: r-help@r-project.org
 Subject: Re: [R] Lattice graphics adding abline line (1:1 line) ???
 
 I have read multiple books and looked at many posts online and can't
 seem to figure out how to add a 1:1 line in lattice xyplot. I've tried
 multiple versions of getting this to work, including trying
 panel.abline(h=0,v=1), panel=function and others.

here is small function which will add arbitrary line(s) to lattice panels

function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = F) 
{
tcL - trellis.currentLayout()
k - 0
for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i, 
j]  0) {
k - k + 1
trellis.focus(panel, j, i, highlight = FALSE)
if (once) 
panel.abline(a = a[k], b = b[k], v = v[k], h = h[k], 
...)
else panel.abline(a = a, b = b, v = v, h = h, ...)
trellis.unfocus()
}
  }


parameter once is used if you want different values in each panel.
Regards
Petr


 
 Second question, how do I get the legend created via auto.key to use
 the
 pch=c(15,16,17,18) and associated colors, these are circle,
 square,triangle and diamond, but the auto.key just plots points with
 different default colors, not the grey scales and symbols that the
 actual plots uses, how do I get these to match. Is auto.key not the way
 to go, again I read on many different methods, but no luck yet.
 
 Thanks,
 Ian
 
 xyplot(Inv591$RichTOL~gbm_tol$fitted, data=Inv591,group=EcoRegion,
 main= Observed vs Predicted for RichTOL (BRT development
 model),xlab=Observed RichTOL, ylab=Predicted RichTOL, xlim=
 c(2,8), ylim= c(2,8), pch=c(15,16,17,18), cex=1.1,
 col=c('grey10','grey30','grey60','grey80'),cex.lab=1.8,
 cex.axis=1.8,font=2, auto.key=list(corner=c(1,0)), panel=function(x,y){
 panel.xyplot(x,y)
 panel.abline(lm(Inv591$RichTOL~gbm_tol$fitted))
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Lattice-
 graphics-with-combined-plot-types-tp790070p4641486.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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@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.


Re: [R] Lattice graphics adding abline line (1:1 line) ???

2012-08-28 Thread Peter Ehlers

On 2012-08-27 15:49, iwaite wrote:

I have read multiple books and looked at many posts online and can't seem to
figure out how to add a 1:1 line in lattice xyplot. I've tried multiple
versions of getting this to work, including trying panel.abline(h=0,v=1),
panel=function and others.

Second question, how do I get the legend created via auto.key to use the
pch=c(15,16,17,18) and associated colors, these are circle, square,triangle
and diamond, but the auto.key just plots points with different default
colors, not the grey scales and symbols that the actual plots uses, how do I
get these to match. Is auto.key not the way to go, again I read on many
different methods, but no luck yet.

Thanks,
 Ian

xyplot(Inv591$RichTOL~gbm_tol$fitted, data=Inv591,group=EcoRegion, main=
Observed vs Predicted for RichTOL (BRT development model),xlab=Observed
RichTOL, ylab=Predicted RichTOL, xlim= c(2,8), ylim= c(2,8),
pch=c(15,16,17,18), cex=1.1,
col=c('grey10','grey30','grey60','grey80'),cex.lab=1.8, cex.axis=1.8,font=2,
auto.key=list(corner=c(1,0)),
panel=function(x,y){
panel.xyplot(x,y)
panel.abline(lm(Inv591$RichTOL~gbm_tol$fitted))



I don't know what a 1:1 line is, but your (nonreproducible)
code suggests that you want a regression line (or lines?).
As for auto.key, it may be better to use the key argument.

Here are a couple of suggestions (using the iris data)
that may help you:

1. If you just want a single regression line for all groups
combined:

  library(lattice)
  xyplot(Sepal.Length ~ Sepal.Width, data = iris,
groups = Species,
pch = 15:17, col = 2:4,
panel = function(x,y,...){
  panel.xyplot(x,y,...)
  panel.lmline(x,y)},
key = list(corner = c(1,0),
text = list(lab = levels(iris[[Species]])),
points = list(pch = 15:17, col = 2:4)))

2. If you want separate regression lines for each group:

  xyplot(Sepal.Length ~ Sepal.Width, data=iris,
groups = Species,
pch = 15:17, col = 2:4,
panel = panel.superpose,
panel.groups = function(x,y,...){
  panel.xyplot(x,y,...)
  panel.lmline(x,y,...)
},
key = list(corner = c(1,0),
text = list(lab = levels(iris[[Species]])),
points = list(pch = 15:17, col = 2:4)))

If you use panel.abline for regression lines, be sure to
specify the regression formula with the reg= argument.

Peter Ehlers

__
R-help@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.


Re: [R] Lattice graphics adding abline line (1:1 line) ???

2012-08-27 Thread iwaite
I have read multiple books and looked at many posts online and can't seem to
figure out how to add a 1:1 line in lattice xyplot. I've tried multiple
versions of getting this to work, including trying panel.abline(h=0,v=1),
panel=function and others. 

Second question, how do I get the legend created via auto.key to use the
pch=c(15,16,17,18) and associated colors, these are circle, square,triangle
and diamond, but the auto.key just plots points with different default
colors, not the grey scales and symbols that the actual plots uses, how do I
get these to match. Is auto.key not the way to go, again I read on many
different methods, but no luck yet.

Thanks,
Ian

xyplot(Inv591$RichTOL~gbm_tol$fitted, data=Inv591,group=EcoRegion, main=
Observed vs Predicted for RichTOL (BRT development model),xlab=Observed
RichTOL, ylab=Predicted RichTOL, xlim= c(2,8), ylim= c(2,8),
pch=c(15,16,17,18), cex=1.1,
col=c('grey10','grey30','grey60','grey80'),cex.lab=1.8, cex.axis=1.8,font=2,
auto.key=list(corner=c(1,0)),
panel=function(x,y){
panel.xyplot(x,y)
panel.abline(lm(Inv591$RichTOL~gbm_tol$fitted)) 



--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-graphics-with-combined-plot-types-tp790070p4641486.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.