R 在 XTS 对象上逐月增长的百分比 [英] R Month by Month Percent Growth on an XTS objects

查看:16
本文介绍了R 在 XTS 对象上逐月增长的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何绘制以下数据的月度增长图:

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

(在 dput 格式中,在约书亚追捕我并在我睡梦中谋杀我之前):

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

推荐答案

定义增长:第一区别?百分比?在任何一种情况下,只需计算然后绘制:

Define growth: first difference? Percentages? In either case just compute and then plot:

R> index(KB) <- as.Date(index(KB))    ## what you have are dates, not datetimes
R> barplot(diff(KB), ylab="Change in value", main="Growth")

您也可以使用标准线图:

You can also use a standard line plot:

R> plot(diff(KB), type='b', ylab="Change in value", main="Growth")

并更改此图的 type= 参数以显示条形等 pp.通常 会绘制百分比变化,但鉴于您的第一个数据点,这在此处是不可接受的(如Gavin)对于这个插图来说是如此不同.

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.

这篇关于R 在 XTS 对象上逐月增长的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆