简体   繁体   English

R时间序列图未显示不同的y轴值,但趋势正确

[英]R time-series plot not showing different y-axis values, but correct trend

I have a big time-series data, the head is: 我有一个大的时间序列数据,头是:

             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

When I try to plot the data in R, it shows the correct trend, but a completely different y-axis scale with a maximum of 12000 (see here: https://docs.google.com/file/d/0B6GUNg-8d30vcG5KdDkxOXR0QkU/edit?usp=sharing )?!? 当我尝试在R中绘制数据时,它显示了正确的趋势,但y轴比例却完全不同,最大值为12000(请参见此处: https : //docs.google.com/file/d/0B6GUNg-8d30vcG5KdDkxOXR0QkU / edit?usp = sharing )?!? However, I never had such a weird problem with any of my other data plots. 但是,我的任何其他数据图都从未遇到过如此怪异的问题。

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

My second question -- my date_time (class: "POSIXlt" "POSIXt") shows "month" by default. 我的第二个问题-我的date_time(类:“ POSIXlt”“ POSIXt”)默认显示为“ month”。 Is it possible to show as "month-year" without using strftime() and/or aggregate()? 是否可以在不使用strftime()和/或aggregate()的情况下显示为“ month-year”?

It is not clear if you have resolved your first problem or not. 目前尚不清楚您是否解决了第一个问题。 Otherwise, for your second question, you can use axis.POSIXct with xaxt="n" to plot the axis manually: 否则,你的第二个问题,你可以使用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')

在此处输入图片说明

Here my data: 这是我的数据:

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM