My data is as follows:
grp = rep(1:2, each = 100)
chr = c(rep(1:10, each = 10), rep(1:10, each = 10))
var = paste (grp, "chr", chr, sep = "")
pos = (rep(1:10, 20))
yvar = rnorm(200)
mydf = data.frame (var, pos, yvar)
require( lattice)
xyplot(yvar ~ pos| factor(var), data = mydf, layout = c(1,10), type = c("g", "h"),
col = "darkolivegreen", lwd = 4)
(1) I want to put different colors to alternate graph / panel - for example - 2chr1
is darkolive green but chr10
is say purple. then again dark olive green and purple so on.
(2) I want to use reverse order of graph means that 2chr9
is at the bottom.
Thanks
Use as.table=TRUE
to change the order of panels and groups
(along with an extended col
vec) to change colo(u)rs.
edit: adjusted order of factor levels
mydf <-
data.frame (var, pos, yvar,
## fvar = factor(var,levels=unique(var)),
fvar = factor(var, levels = c(outer(2:1, 1:10, paste, sep="chr"))))
xyplot(yvar ~ pos| fvar,
groups=fvar,
data = mydf, layout = c(1,10,2), type = c("g", "h"),
col = c("darkolivegreen","purple"), lwd = 4, as.table=TRUE)
The extended layout
command gives two pages.
Alternatively, a side-by-side layout might be nice:
library(latticeExtra)
useOuterStrips(xyplot(yvar ~ pos|factor(grp)*factor(chr),
groups=grp,
col=c("darkolivegreen","purple"),
data = mydf, layout = c(2,10), type = c("g", "h"),
lwd = 4, as.table=TRUE))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With