gpt4 book ai didi

r - 获取日期显示在 R 中的plot.STL 方法的x 轴上

转载 作者:行者123 更新时间:2023-12-02 03:23:51 25 4
gpt4 key购买 nike

我想知道是否有人知道如何让日期出现在 STL 图的 x 轴上。

 res<- (stl(ts(data[,variable],frequency=52,start=as.Date(data[1,date]) ),s.window="per",robust=TRUE) ) 
plot(res)

enter image description here

然而,这只是在图表底部生成一些 unicode 标签,我也尝试将 as.Date 更改为 as.character 但这不起作用。

输出一些数据:

structure(c("2007-01-01", "2007-01-08", "2007-01-15", "2007-01-22", 
"2007-01-29", "2007-02-05", "2007-02-12", "2007-02-19", "2007-02-26",
"2007-03-05", "2007-03-12", "2007-03-19", "2007-03-26", "2007-04-02",
"2007-04-09", "2007-04-16", "2007-04-23", "2007-04-30", "2007-05-07",
"2007-05-14", "2007-05-21", "2007-05-28", "2007-06-04", "2007-06-11",
"2007-06-18", "2007-06-25", "2007-07-02", "2007-07-09", "2007-07-16",
"2007-07-23", "2007-07-30", "2007-08-06", "2007-08-13", "2007-08-20",
"2007-08-27", "2007-09-03", "2007-09-10", "2007-09-17", "2007-09-24",
"2007-10-01", "2007-10-08", "2007-10-15", "2007-10-22", "2007-10-29",
"2007-11-05", "2007-11-12", "2007-11-19", "2007-11-26", "2007-12-03",
"2007-12-10", "2007-12-17", "2007-12-24", "2007-12-31", "2008-01-07",
"2008-01-14", "2008-01-21", "2008-01-28", "2008-02-04", "2008-02-11",
"2008-02-18", "2008-02-25", "2008-03-03", "2008-03-10", "2008-03-17",
"2008-03-24", "2008-03-31", "2008-04-07", "2008-04-14", "2008-04-21",
"2008-04-28", "2008-05-05", "2008-05-12", "2008-05-19", "2008-05-26",
"2008-06-02", "2008-06-09", "2008-06-16", "2008-06-23", "2008-06-30",
"2008-07-07", "2008-07-14", "2008-07-21", "2008-07-28", "2008-08-04",
"2008-08-11", "2008-08-18", "2008-08-25", "2008-09-01", "2008-09-08",
"2008-09-15", "2008-09-22", "2008-09-29", "2008-10-06", "2008-10-13",
"2008-10-20", "2008-10-27", "2008-11-03", "2008-11-10", "2008-11-17",
"2008-11-24", "2008-12-01", "2008-12-08", "2008-12-15", "2008-12-22",
"2008-12-29", "2009-01-05", "2009-01-12", "2009-01-19", "2009-01-26",
"2009-02-02", "2009-02-09", "2009-02-16", "2009-02-23", "2009-03-02",
"2009-03-09", "2009-03-16", "2009-03-23", "2009-03-30", "2009-04-06",
"2009-04-13", "2009-04-20", "2009-04-27", "2009-05-04", "2009-05-11",
"2009-05-18", "2009-05-25", "2009-06-01", "2009-06-08", "2009-06-15",
"2009-06-22", "2009-06-29", "2009-07-06", "2009-07-13", "2009-07-20",
"2009-07-27", "2009-08-03", "2009-08-10", "2009-08-17", "2009-08-24",
"2009-08-31", "2009-09-07", "2009-09-14", "2009-09-21", "2009-09-28",
"2009-10-05", "2009-10-12", "2009-10-19", "2009-10-26", "2009-11-02",
"2009-11-09", "2009-11-16", "2009-11-23", "2009-11-30", "2009-12-07",
"2009-12-14", "2009-12-21", "2009-12-28", "2010-01-04", "2010-01-11",
"2010-01-18", "2010-01-25", "2010-02-01", "2010-02-08", "2010-02-15",
"2010-02-22", "2010-03-01", "2010-03-08", "2010-03-15", "2010-03-22",
"2010-03-29", "2010-04-05", "2010-04-12", "2010-04-19", "2010-04-26",
"2010-05-03", "2010-05-10", "2010-05-17", "2010-05-24", "2010-05-31",
"2010-06-07", "2010-06-14", "2010-06-21", "2010-06-28", "2010-07-05",
"2010-07-12", "2010-07-19", "2010-07-26", "2010-08-02", "2010-08-09",
"2010-08-16", "2010-08-23", "2010-08-30", "2010-09-06", "2010-09-13",
"2010-09-20", "2010-09-27", "2010-10-04", "2010-10-11", "2010-10-18",
"2010-10-25", "2010-11-01", "2010-11-08", "2010-11-15", "2010-11-22",
"2010-11-29", "2010-12-06", "2010-12-13", "2010-12-20", "2010-12-27",
"2011-01-03", "2011-01-10", "2011-01-17", "2011-01-24", "2011-01-31",
"2011-02-07", "2011-02-14", "2011-02-21", "2011-02-28", "2011-03-07",
"2011-03-14", "2011-03-21", "2011-03-28", "2011-04-04", "2011-04-11",
"2011-04-18", "2011-04-25", "2011-05-02", "2011-05-09", "2011-05-16",
"2011-05-23", "2011-05-30", "2011-06-06", "2011-06-13", "2011-06-20",
"2011-06-27", "2011-07-04", "2011-07-11", "2011-07-18", "2011-07-25",
"2011-08-01", "2011-08-08", "2011-08-15", "2011-08-22", "2011-08-29",
"2011-09-05", "2011-09-12", "2011-09-19", "2011-09-26", "2011-10-03",
"2011-10-10", "2011-10-17", "2011-10-24", "2011-10-31", "2011-11-07",
"2011-11-14", "2011-11-21", "2011-11-28", "2011-12-05", "2011-12-12",
"2011-12-19", "2011-12-26", "442573", "452832", "452785", "459228",
"479509", "477631", "465619", "462001", "485567", "462381", "456059",
"457401", "474094", "468766", "456945", "539126", "545640", "511801",
"486619", "484430", "481428", "470622", "479677", "486755", "477617",
"483656", "497479", "493436", "480080", "481527", "516029", "532349",
"503939", "472171", "461550", "504532", "489715", "480032", "488376",
"470772", "467395", "488155", "455712", "474456", "471237", "482943",
"459320", "456956", "465056", "461930", "441201", "451255", "464508",
"449199", "455411", "476323", "521761", "513416", "521070", "497596",
"485461", "485593", "461148", "429938", "441207", "459484", "462099",
"469285", "454395", "456729", "469251", "517727", "526719", "477985",
"484538", "469766", "472399", "481162", "479039", "481071", "485068",
"462108", "459079", "452410", "488574", "502166", "504323", "514529",
"524206", "504315", "462935", "461899", "461551", "455491", "456857",
"443314", "454586", "458943", "450555", "454311", "442808", "440126",
"414876", "415787", "413352", "423864", "448319", "415440", "431948",
"433313", "448509", "436400", "454154", "454183", "447735", "452220",
"451433", "472808", "446767", "426595", "463693", "435673", "452704",
"456828", "465069", "448685", "457353", "443859", "463972", "480139",
"493342", "500982", "529602", "527365", "512005", "484585", "455007",
"470006", "477522", "443956", "459038", "488877", "466669", "476242",
"470862", "457298", "466438", "454062", "460216", "466645", "445113",
"457255", "451553", "451504", "447991", "435100", "416140", "481390",
"489041", "496984", "486245", "478191", "455201", "448085", "459097",
"480859", "490248", "462523", "489755", "468391", "460229", "481276",
"472845", "481099", "476435", "487314", "475043", "476847", "461928",
"483488", "479379", "456732", "461538", "480773", "471101", "459898",
"482129", "464356", "459420", "457850", "456764", "438152", "467928",
"464732", "458767", "470256", "449488", "433263", "428548", "435099",
"429163", "424251", "434723", "425841", "399498", "418791", "405051",
"385037", "425144", "418296", "397644", "414283", "431907", "429117",
"424862", "439664", "432791", "443588", "434985", "442418", "445760",
"449290", "451412", "456247", "444372", "441390", "458192", "456435",
"450670", "447609", "439083", "464513", "462784", "439423", "450857",
"442374", "447753", "440207", "435254", "430841", "437233", "426523",
"430127", "431305", "470244", "508878", "511064", "504182", "462076",
"452218", "426535", "436892", "459008", "441449", "438783", "427497",
"432275", "436745", "423068", "429574", "416074"), .Dim = c(261L,
2L))

最佳答案

问题在于您如何创建时间序列对象。?ts 会给你

start : the time of the first observation. Either a single number or a vector of two integers, which specify a natural time unit and a (1-based) number of samples into the time unit.

由于你的数据是从2007年1月1日开始的,并且是周数据,所以你必须指定c(2007,1),注意这里的“1”表示数据从2007年第1周开始,因为数据为每周。此处频率应设置为 52,因为每年 52 个周期/周后将从 2007 年更改为 2008 年。

这应该有效

res<- (stl(ts(data[,2],frequency=52,start=c(2007,1 )),s.window="per",robust=TRUE) )

enter image description here

关于r - 获取日期显示在 R 中的plot.STL 方法的x 轴上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com