2012-11-21 41 views
0

我想更改圖面板的順序。目前,我有3個不同類別的專欄,我想要的是1個專欄,其中3個專欄堆疊在一起。它們都具有相同的X軸(在這種情況下爲主成分分析的值),然後對於我的3個類別中的每個類別,季節冬季或夏季仍將在Y軸上。這是我有:在r中更改圖的面板

bwplot(Comp1~ Season|Repro, data = moose, 
    strip = strip.custom(var.name = c("f", "fc", "m"),strip.names=F, bg = 'white'), 
    cex = .5, layout = c(3, 1), 
    xlab = "Principal component 1", ylab = "Season", 
    par.settings = list(
     box.rectangle = list(col = 1), 
     box.umbrella = list(col = 1), 
     plot.symbol = list(cex = .5, col = 1)), 
     scales = list(x = list(relation = "same"), 
        y = list(relation = "same"))) 

另一種選擇是在箱線圖沿X軸的2個賽季的地方,PCA在Y,但2個賽季被打破:enter image description here 我用我的代碼創建了這個在那些季節內分成三組。與上圖中有3個面板不同,我需要2個面板(夏季和冬季),然後在這2個面板中,將冬季的f,fc,m分組,並在下一個面板中(或在同一圖形中)夏季的f,fc,m。基本上就像下一張照片一樣,但把它放在一邊。我用這個代碼,接着使殘存的代碼從上述生成此圖表:bwplot(Season ~Comp1|Repro, data = moose,

enter image description here

下面是樣本數據來嘗試與所述代碼。

structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 
6L, 6L, 6L, 6L, 7L, 7L), .Label = c("F07002", "F07004", "F07005", 
"M07016", "M10007", "M10011", "M10015"), class = "factor"), Season = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L), .Label = c("SUM", 
"WIN"), class = "factor"), Time = structure(c(1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 
1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("day", "night" 
), class = "factor"), Repro = structure(c(2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("f", "fc", "m" 
), class = "factor"), Comp1 = c(-0.380080882, -0.610696209, -0.249409859, 
-0.409333188, -0.222490545, -0.204438065, -0.345230884, -0.142284942, 
0.750928418, 1.002325431, 0.450508246, 0.473959627, 1.059173278, 
0.911574612, 1.394915031, -0.448160403, -0.470799127, -0.760760938, 
-0.923465222, -1.522742066, -1.933918532, -0.83699801, -1.240214807, 
0.878163747, 0.756748992, 1.931795511, 1.802387012, 1.67483398, 
1.448883802, 0.974062472, 1.234001613, -0.439149936, -0.826745549, 
-0.42835036, -0.871512952, 0.17532518, 0.559407728, 0.976634392, 
-0.202405922, -0.633821539, -0.306163898, -0.302261589, 1.218779672, 
1.568575464, -0.310174732, -0.761785902), ln1wr = c(0.925765702, 
0.90999093, 1.109420337, 1.125676072, 1.081194815, 1.102770299, 
0.981029233, 1.019605156, 0.892407791, 0.894740178, 0.990098659, 
0.998570934, 1.280544881, 1.283292174, 0.152892746, 0.000499875, 
0.00039992, 0, 0, 1.820962221, 1.72698981, 1.829087366, 1.728020628, 
0.0009995, 0.000899595, 0, 0, 0.003693172, 0.003493889, 1.537705578, 
1.520475543, 1.410401436, 1.40550858, 1.258972223, 1.255302598, 
1.4981711, 1.505964504, 1.446048016, 1.132530507, 1.134944218, 
1.149653885, 1.148798304, 1.140553656, 1.14762465, 0.421797669, 
0.4069307)), .Names = c("ID", "Season", "Time", "Repro", "Comp1", 
"ln1wr"), class = "data.frame", row.names = c(NA, -46L)) 
+0

我覺得你只是想'水平= TRUE',但目前還不清楚,我反正。像往常一樣的數據例子,即使用隨機數字代替真實值,也會有很大幫助。 –

+0

@DWin添加你的命令改變了從箱形圖到散點圖的所有內容,並沿着Y軸分散它們。我編輯並添加了示例數據。 – Kerry

+0

你試過了:'bwplot(Season〜Comp1 | Repro,...,horizo​​ntal = TRUE,)'? –

回答

0

還沒完全確定你想要什麼,但使用兩個因素的公式興田LHS的互動功能,可能讓你轉換爲水平TRUE後需要什麼。

bwplot(interaction(Season,Repro) ~ Comp1, data = moose, 
    cex = .5, 
    xlab = "Principal component 1", ylab = "Season", horizontal=TRUE, 
    par.settings = list(
     box.rectangle = list(col = 1), 
     box.umbrella = list(col = 1), 
     plot.symbol = list(cex = .5, col = 1)), 
     scales = list(x = list(relation = "same"), 
        y = list(relation = "same"))) 

enter image description here