On Jan 15, 2009, at 9:27 PM, jimdare wrote:
Dear R-Users
I have 2 questions to do with XYplot.
1)
I am trying to use the XYplot function to generate multiple line
graphs with
the legend outside the plot.
I am using the following loop for each graph:
library(lattice)
for (i in x.sp){
xyplot(Catch~Year, df, groups = Stock, type="a",auto.key =
list(space = "top", points = FALSE, lines = TRUE,columns = 4))
}
From the help on package lattice:
"Note
High level Lattice functions (like xyplot) are different from
conventional R graphics functions because they don't actually draw
anything. Instead, they return an object of class "trellis" which has
to be then printed or plotted to create the actual plot. This is
normally done automatically, but not when the high level functions are
called inside another function (most often source) or other contexts
where automatic printing is suppressed (e.g. for or while loops). In
such situations, an explicit call to print or plot is required."
Or the FAQ:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f
When I run the script I don't get any output graphs, however if I
change
'XYplot' to 'plot', or generate the plots manually using XYplot, It
seems to
work. Is there a bug of some sort or is it me?
2)
How do I remove the "top" and "right" axis from a plot? If I add
'axis(side
= c("bottom", "left")' to the xyplot call it comes up with the
message:
Error in axis(side = c("bottom", "left")) :
plot.new has not been called yet