Skip to content
Prev 19096 / 398498 Next

Writing text in lattice graphics

I'm trying to obtain a set of regression lines obtained for different values 
of a factor using lattice. I would like to add a string to each panel showing 
the R^2 value of the respective line, but I'm having difficulties positioning 
the text (namely on which coordinates to give to the "ltext" function).
Here is what I'm using (I've used ?? for the things I would like you to be so 
kind to help me on how to fill in).
panel=function(x,y,...) {
		panel.xyplot(x,y,...)
		panel.lmline(x,y,...)
		ltext(??, ??, round(summary(lm(y ~ x))$r.squared,3))
	})

I would like the R^2 values to appear in the top left corner of each of the 
panels I get.
I've tried fixed values for the "x", "y" parameters of "ltext", but as I'm 
using different X scales for each panel things get messy...

I'm using R 1.4.1 on a Windows 2000 machine.

Thank you in advance.