[R] Evaluated expression in lattice key

Duncan Mackay dulcalma at bigpond.com
Tue Jan 20 00:23:15 CET 2015

I do not think any one has replied to this.

Having 2 keys I think comes under the bit in the help under legend.

I have not got time at the moment but see 

and have a look at


and the following 



Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Naresh
Sent: Saturday, 17 January 2015 23:08
To: r-help at r-project.org
Subject: [R] Evaluated expression in lattice key

In a conditional xyplot, I would like to add some numerical results in every
panel.  Consider below example.
df <- data.frame(x = rnorm(100), name = "A")
df <- within(df, {y <- x + 0.2 * rnorm(100)})
df2 <- data.frame(x = rnorm(100), y = rnorm(100), name = "B")
df <- rbind(df, df2)

with(df, xyplot(y ~ x | name, data = df, 
  panel = function(x, y, ...){
  	panel.xyplot(x, y)
  	panel.lmline(x, y, col = "grey")
  auto.key = list(corner = c(1,0), x = 0.9, y = 0.1, 
  text = substitute(expression(R^{2} == myval), 
  list(myval = summary(lm(y ~ x))$r.squared)))))
There are two problems with this plot.  First, there is only one key.  I
want two different keys for the two panels.  
Second, R^2 is for all data.  For each panel, I want R^2 calculated using
only the data plotted in that panel.  
Please help.
	[[alternative HTML version deleted]]

R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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