[R] plotting step functions in plot vs. xyplot
Dylan Beaudette
dylan.beaudette at gmail.com
Mon Dec 3 01:29:37 CET 2007
Hi,
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[1] <- prop[2]
## 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:
sessionInfo()
R version 2.4.1 (2006-12-18)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C
attached base packages:
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
[7] "base"
other attached packages:
lattice
"0.14-17"
could it be that my version of R and lattice is just too old?
thanks in advance!
Dylan
More information about the R-help
mailing list