在r中更改图表的面板

时间:2012-11-21 17:50:43

标签: r graph boxplot

我想更改图表面板的顺序。目前我有3列我的不同类,我想要的是1列,其中3个类堆叠在彼此上面。它们都具有相同的X轴(在这种情况下是主成分分析的值),然后对于我的3个类别中的每一个,季节冬季或夏季仍将在Y轴上。这就是我所拥有的:enter image description here 我用我的代码创建了这个:

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个季节,在Y的PCA上的箱形图,但是在这些季节中将2个季节分成3组。与上面有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))

1 个答案:

答案 0 :(得分:0)

仍然不能确切地确定你想要什么,但在公式的两个因素上使用交互功能可以在转换为水平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