【问题标题】:Panel plot using lattice package in R在 R 中使用 lattice 包的面板图
【发布时间】:2014-09-06 15:33:12
【问题描述】:

我想使用 lattice 制作一个 xyplot,其中 2 个面板相互重叠,对应于具有 2 个级别(工作日和周末)的变量(日期)。我的数据框如下所示:

 interval    date      steps
1        0 Weekday 2.25115556
2        5 Weekday 0.44528000
3       10 Weekday 0.17316889
4       15 Weekday 0.19789778
5       20 Weekday 0.09895556
6       25 Weekday 1.59035111
 .
 .
 .  
289        0 Weekend   0.21462500
290        5 Weekend   0.04245000
291       10 Weekend   0.01651250
292       15 Weekend   0.01886250
293       20 Weekend   0.00943750
294       25 Weekend   3.51178750

我使用了以下代码:

xyplot(steps ~ interval| levels(activity.week.mean$date), 
           data = activity.week.mean,
           type = "l",
           xlab = "Interval",
           ylab = "Number of steps",
           layout=c(1,2))

发生的情况是,我得到了 2 个面板,它们都具有周末和工作日的分布,但我每个都需要一个。提前致谢。

【问题讨论】:

  • 你试过steps~interval|date吗?很高兴您包含了数据,但总的来说,当您使用 dput(activity.week.mean) 的输出时,它对尝试使用这些数据的人更有帮助
  • 完美!我实际上早些时候尝试过,但那是在我将日期更改为具有 2 个级别的因子变量之前,这会弄乱结果。

标签: r panel lattice


【解决方案1】:

您应该使用 |factor(date) 或仅使用 |date 而不是 |levels(date)

xyplot(steps~interval|factor(date),
       type='l',layout=c(1,2),
       xlab='Interval',ylab='Number of Steps')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-10
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多