【问题标题】:R time-series plot not showing different y-axis values, but correct trendR 时间序列图未显示不同的 y 轴值,但趋势正确
【发布时间】:2013-07-06 14:03:57
【问题描述】:

我有一个大的时间序列数据,头部是:

             date_time         V1       V2 V3      V4     V5
13 2012-10-13 17:40:00 10/13/2012 17:40:00  0 15.8604 25.706
14 2012-10-13 18:00:00 10/13/2012 18:00:00  0 15.8508 25.688
15 2012-10-13 18:20:00 10/13/2012 18:20:00  0 15.8615 25.688
16 2012-10-13 18:40:00 10/13/2012 18:40:00  0 15.8637 25.686
17 2012-10-13 19:00:00 10/13/2012 19:00:00  0  15.868 25.686
18 2012-10-13 19:20:00 10/13/2012 19:20:00  0 15.8701 25.686

当我尝试在 R 中绘制数据时,它显示了正确的趋势,但 y 轴刻度完全不同,最大值为 12000(参见此处:https://docs.google.com/file/d/0B6GUNg-8d30vcG5KdDkxOXR0QkU/edit?usp=sharing)?!?但是,我的任何其他数据图都没有遇到过如此奇怪的问题。

plot(date_time, data$V4, type='l', ylab = '??')

我的第二个问题——我的 date_time(类:“POSIXlt”“POSIXt”)默认显示“月”。是否可以在不使用 strftime() 和/或 aggregate() 的情况下显示为“月-年”?

【问题讨论】:

  • 添加数据前几行的dput。这样可以更轻松地查看正在发生的事情。
  • 我的前12行数据不一样,所以我用data

标签: r time-series


【解决方案1】:

尚不清楚您是否解决了第一个问题。否则,对于第二个问题,您可以使用 axis.POSIXct 和 xaxt="n" 手动绘制轴:

plot(x=data$date_time, y=data$V4, type='l', ylab = '??',xaxt="n") ## note here 
axis.POSIXct(1, at=data$date_time,format='%b %Y')

这是我的数据:

structure(list(date_time = structure(c(1350142800, 1350144000, 
1350145200, 1350146400, 1350147600, 1350148800), class = c("POSIXct", 
"POSIXt"), tzone = ""), V1 = structure(c(1L, 1L, 1L, 1L, 1L, 
1L), .Names = c("13", "14", "15", "16", "17", "18"), .Label = "10/13/2012", class = "factor"), 
    V2 = structure(1:6, .Names = c("13", "14", "15", "16", "17", 
    "18"), .Label = c("17:40:00", "18:00:00", "18:20:00", "18:40:00", 
    "19:00:00", "19:20:00"), class = "factor"), V3 = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L), .Names = c("13", "14", "15", "16", "17", 
    "18"), .Label = "0", class = "factor"), V4 = structure(c(2L, 
    1L, 3L, 4L, 5L, 6L), .Names = c("13", "14", "15", "16", "17", 
    "18"), .Label = c("15.8508", "15.8604", "15.8615", "15.8637", 
    "15.8680", "15.8701"), class = "factor"), V5 = structure(c(3L, 
    2L, 2L, 1L, 1L, 1L), .Names = c("13", "14", "15", "16", "17", 
    "18"), .Label = c("25.686", "25.688", "25.706"), class = "factor")), .Names = c("date_time", 
"V1", "V2", "V3", "V4", "V5"), row.names = c("13", "14", "15", 
"16", "17", "18"), class = "data.frame")

【讨论】:

  • 我的第一个问题已部分解决。您的解决方案运行良好,但由于数据点过多,刻度线会形成一条粗黑线(此处为:docs.google.com/file/d/0B6GUNg-8d30vdEdpWTJLSmd1V0E/…)。看起来很奇怪,有什么建议吗?
  • @ToNoY 你应该给at 论点更少的分数。例如,您可以像这样at=data$date_time[c(T,rep(F,10))] 给 ecah 10 分
  • 谢谢...我正在阅读axis.POSIXct帮助文件,但当时没用...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-05
  • 1970-01-01
  • 1970-01-01
  • 2014-09-04
  • 1970-01-01
  • 2018-08-17
相关资源
最近更新 更多