I'm pretty sure that you need to wrap the xyplot() in print()
print(xyplot( den$y ~ den$x, xlab="Points", type = "l",main =
main2, col = 1, ... ) )
I don't know the labeling you want off the top of my head. You might be
able to do it with the axes() function or you may need to use text() but
I think you know as much about them and using them in a panel function
as I do.
Paul Lasky wrote:
I know this is another tiresome "scoping" question, but I can't seem
to get a Trellis plot with panel functions to work when called from a
function:
What I want to do is graph prob density, put some quantile vertical
lines on the graph, and place some text on the graph labeling the
vertical lines; the following code (without attempting the labeling)
doesn't work:
myFunction = function( obj ) {
#
den = density( obj$score, n=100, width = 29 )
quant = quantile( obj$score, c( 0.1, 0.5, 0.9 ) )
main2 = "My Stuff"
#
xyplot( den$y ~ den$x, xlab="Points", type = "l",main = main2,
col = 1,
panel = function(x, y) {
panel.abline( v = quant, lty = 2 )
}
)
}
Also what is the code for Labeling the vertical quantile lines
with text at the bottom such as " 10%", "Median", "90%"?
A panel.text function isn't available.
Producing this plot within a function is easy to do with the
old-fashioned plot function. But Trellis plots seem to be so
difficult to work with that, frankly, most of the time they aren't
worth the effort. In this instance, however it would be desirable
from a publication standpoint to produce a Trellis plot.
Paul Lasky
P & B Consultants.
|