I am following the book "R in action" P389 example to arrange hist panels in the following lattice graph:
library(lattice)
graph1 <- histogram(~ height | voice.part, data = singer,
main = "Heights of Choral Singers by Voice Part")
graph2 <- densityplot(~ height, data = singer, group = voice.part,
plot.points = FALSE, auto.key = list(columns = 4))
plot(graph1, position=c(0, .3, 1, 1))
plot(graph2, position=c(0, 0, 1, .3), newpage = FALSE)
As instruction from the book, I use index.cond
to change the order of the graph, like
plot(graph1, position = c(0, .3, 1, 1),
index.cond = list(c(2, 4, 6, 8, 1, 3, 5, 7)))
But the order in the graph does not change. Can anyone help me of this?
I also notice index.cond
is not in the help of ?plot
"index.cond", as other arguments described in ?xyplot
are either passed to the functions that create "trellis" objects or to the update
methods. So, in this case, you can
create "graph1" by passing "index.cond" to histogram
:
histogram(~ height | voice.part, data = singer,
main = "Heights of Choral Singers by Voice Part",
index.cond = list(c(2, 4, 6, 8, 1, 3, 5, 7)))
, use update
:
update(graph1, index.cond = list(c(2, 4, 6, 8, 1, 3, 5, 7)))
or use "["
:
graph1[c(2, 4, 6, 8, 1, 3, 5, 7)]