R XTS 对象的逐月增长百分比
我如何绘制以下数据的逐月增长:(
A
2008-07-01 0
2008-08-01 87
2008-09-01 257
2008-10-01 294
2008-11-01 325
2008-12-01 299
以 dput 格式,在约书亚追捕我并在睡梦中谋杀我之前):
structure(c(0L, 87L, 257L, 294L, 325L, 299L), .indexCLASS = c("POSIXt",
"POSIXct"), .indexTZ = "", index = structure(c(1214884800, 1217563200,
1220241600, 1222833600, 1225512000, 1228107600), tzone = "", tclass = c("POSIXt",
"POSIXct")), .Dim = c(6L, 1L), .Dimnames = list(NULL, "A"), class = c("xts",
"zoo"))
How might I plot month to month growth for the following data:
A
2008-07-01 0
2008-08-01 87
2008-09-01 257
2008-10-01 294
2008-11-01 325
2008-12-01 299
(In dput format, before Joshua hunts me down and murders me in my sleep):
structure(c(0L, 87L, 257L, 294L, 325L, 299L), .indexCLASS = c("POSIXt",
"POSIXct"), .indexTZ = "", index = structure(c(1214884800, 1217563200,
1220241600, 1222833600, 1225512000, 1228107600), tzone = "", tclass = c("POSIXt",
"POSIXct")), .Dim = c(6L, 1L), .Dimnames = list(NULL, "A"), class = c("xts",
"zoo"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义增长:第一个区别?百分比?无论哪种情况,只需计算然后绘图:
您还可以使用标准线图:
并更改此图的
type=
参数以显示条形图等页。通常 将绘制百分比变化,但考虑到您的第一个数据点在这里是不可接受的(正如 Gavin 所指出的),因此它对于这个插图来说是不同的。Define growth: first difference? Percentages? In either case just compute and then plot:
You can also use a standard line plot:
and change the
type=
argument of this plot to show bars etc pp. Normally would plot percentage changes but given your first datapoint this is inadmissible here (as noted by Gavin) so diffs it is for this illustration.使用对象
dat
中的dput()
数据,并假设您的意思是与上个月相比的月份百分比变化,那么:(忘记了绘图)
不确定如何最好地处理第二个月 - 增长百分比是无限的...
Using your
dput()
data in objectdat
, and assuming you mean the month percentage change over previous month, then:(Forgot the plot)
Not sure how best to handle the second month - % growth was infinite...