0

我想制作一个箱线图,显示花费在行为上的时间(警报)如何受两个变量(期间 = 早上/下午和访客级别 = 高/低)的影响。

Alert ~ Period + Vis.Level

“警报”是一组 12 个数字,显示清醒所花费的时间量,其他两个数字是重要的分类变量。我看过其他例子,但似乎没有一个适合这类问题。

我知道我正在寻找的图表上会有 4 个箱线图......据说

  • PeriodMorning+Vis.LevelHigh
  • PeriodMorning+Vis.LevelLow
  • PeriodAfternoon+Vis.LevelHigh
  • PeriodAfternoon+Vis.LevelLow

在 x 轴上。

任何帮助都会很棒!

   Alert Vis.Level    Period
1    0.0       Low   Morning
2    1.0       Low   Morning
3    0.0       Low   Morning
4   11.5       Low Afternoon
5    6.0       Low Afternoon
6   11.5       Low Afternoon
7    0.0      High   Morning
8    0.0      High   Morning
9    0.0      High   Morning
10   0.0      High Afternoon
11   2.5      High Afternoon
12   7.5      High Afternoon
4

1 回答 1

4

假设您的数据看起来像这样

dd <- structure(list(Alert = c(0, 1, 0, 11.5, 6, 11.5, 0, 0, 0, 0, 
2.5, 7.5), Vis.Level = c("Low", "Low", "Low", "Low", "Low", "Low", 
"High", "High", "High", "High", "High", "High"), Period = c("Morning", 
"Morning", "Morning", "Afternoon", "Afternoon", "Afternoon", 
"Morning", "Morning", "Morning", "Afternoon", "Afternoon", "Afternoon"
)), .Names = c("Alert", "Vis.Level", "Period"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"))

然后你要确保你的因素在正确的顺序

dd$Period<-factor(dd$Period, levels=c("Morning","Afternoon"))
dd$Vis.Level<-factor(dd$Vis.Level, levels=c("Low","High"))

然后你可以做

boxplot(Alert~Period+Vis.Level, dd)

或者你可以得到你要求的确切布局

boxplot(Alert~interaction(Period, Vis.Level, lex.order=T), dd)

在此处输入图像描述

于 2014-08-18T18:48:37.623 回答