[R] plotting step functions in plot vs. xyplot
dylan.beaudette at gmail.com
Mon Dec 3 01:29:37 CET 2007
I have noticed an odd inconsistency when plotting a 'step' function
(type='s') in xyplot() vs. plot().
For example, given the following data:
## generate some profile depths: 0 - 150, in 10 cm increments
depth <- seq(0,150, by=10)
## generate some property: random numbers in this case
prop <- rnorm(n=length(depth), mean=15, sd=2)
## since the 0 is not a depth, and we would like the graph to start from 0
## make the first property row (associated with depth 0) the same as the second
## property row
prop <- prop
## combine into a table: data read in from a spread sheet would
already be in this format
soil <- data.frame(depth=depth, prop=prop)
## simple depth plot, as steps: looks good!
plot(depth ~ prop, data=soil, ylim=c(150,0), type='s', ylab='Depth',
xlab='Property', main='Property vs. Depth Plot')
## now try it with lattice graphics:yuck!
xyplot(depth ~ prop, data=soil, ylim=c(160,-5), type='s',
ylab='Depth', xlab='Property', main='Property vs. Depth Plot')
it looks like the data isn't rotated (?) correctly - i.e. the axis and
data do not match.
Now, am I mis-interpreting the meaning of type='s' in lattice graphics?
here is my R session info:
R version 2.4.1 (2006-12-18)
attached base packages:
 "stats" "graphics" "grDevices" "utils" "datasets" "methods"
other attached packages:
could it be that my version of R and lattice is just too old?
thanks in advance!
More information about the R-help