Dan Kortschak
2009-Nov-24 00:23 UTC
[R] problem: howto see ylim (or equivalent) within a custom panel function
Hello, I am plotting a set of data where subsets are of different length and not all sites are noted in the data sets. To indicate the extent of sites, I am marking this with a line on the xyplot being produced: require(lattice) lengths<-as.integer(runif(10)*100) results <- matrix(ncol=3) for (i in 1:10) { gap <- 1-runif(1)/10 pos <- 1:as.integer(lengths[i]*gap) seq <- rep.int(i,as.integer(lengths[i]*gap)) freq <- rgamma(as.integer(lengths[i]*gap), 1) results <- rbind(results, cbind(pos, seq, freq)) } results <- as.data.frame(results) panel.xyextent <- function(x, y, ...) { panel.xyplot(x, y, ...) panel.lines(c(0, lengths[panel.number()]), c(0,0), col="red") } xyplot(freq~pos | seq, layout=c(1,5,2), data=results, panel=panel.xyextent) I would like the hairline to be placed below the origin, by some factor of ylim or 'max(x for all seq)' (a number of datasets have different max values - I have not included this in the example - so a constant offset results in different placement between datasets). I'm not sure where to start with this. Also, I am sure that the example setup above is not the best way to put all the values into results. I imagine that one of the *apply functions would be appropriate, but I'm not sure how. Can anyone comment on this? thank you Dan