2011-12-15 54 views
5

我的數據指定顏色不同面/面板如下:R:在晶格

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希望把不同的顏色來替代圖/面板 - 例如 - 2chr1是darkolive綠色,但chr10是說紫色。然後再次黑橄欖綠和紫色等。

(2)我想用圖形的相反的順序意味着2chr9是在底部。

感謝

enter image description here

+0

我覺得次要情節被稱爲「板」在'lattice`世界和「面」在'ggplot`世界... – 2011-12-15 15:22:44

回答

6

使用as.table=TRUE改變面板的順序和groups(帶擴展col VEC一起)改變科洛(U)RS。

編輯:因子水平的調整順序

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) 

擴展layout命令給出了兩頁。

enter image description here

或者,並排側佈局可能是好的:

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)) 

enter image description here

+0

@奔,謝謝,AS.TABLE作品,但山坳不列入生產什麼我打算做。我不想把不同顏色的替代值,而到備用面板... – jon 2011-12-15 15:22:34