全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4411 4
2013-10-31
悬赏 100 个论坛币 已解决
我使用的是R studio 0.97551,运行在Windows XP系统下。

表示最近尝试想把多个时间序列画在一张plot上,代码如下(方便各位操作使用的是系统自带的Canada数据包,实际上用的是自己的time series)
library(xts)  library(xtsExtra)
library(sandwich)
library(urca)
library(timeSeries)
library(timeDate)
library(zoo)
library(MASS)
library(strucchange)
library(lmtest)
library(vars)
data(Canada)  #加载一个系统自带的数据包
plot.xts(Canada,screens=1)

虽然最后可以达到我想要的目的,但是很明显一个y轴是不够的。当我想用axis语句添加y轴的时候貌似语句失灵了,我查过xts package的解释,大概是说用了这个数据包(包括quantmod)R自带的画图语句就失灵了。
求问版上的众位高手,这种问题怎么解决?我比较心水xts包的绘图功能,但是y轴不能画真的是个问题;传统方法的plot+line貌似对于时间序列处理效果也不是很理想(就画图效果而言)
谢谢!

p.s  试过了其他主流方法如par+line,或者各种R语言推荐的


另外,求问以下几个问题(金币已经追加):

1。如果我用这段代码绘图,那么Rsweave文件对应的代码还是适用于绘图的那一套代码吗?因为我曾经试过生成pdf,总有问题

2。如果低版本的R是不是无法加载这么多的package,也不能生成pdf文件?

最佳答案

zhangyangsmith 查看完整内容

I have little knowledge on time series or ananlysis of economic data. But I am interested to do (all kinds of) plots in R. I find it quite rare that one given plot cannot be implemented in R. There must be a reason that the author of the packages make it impossible to add another axis in the plot yet I am not able to give any hint. With all that said, if you do want to do the plot in your way you ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-10-31 11:08:32
I have little knowledge on time series or ananlysis of economic data. But I am interested to do (all kinds of) plots in R. I find it quite rare that one given plot cannot be implemented in R. There must be a reason that the author of the packages make it impossible to add another axis in the plot yet I am not able to give any hint.
With all that said, if you do want to do the plot in your way you may need to construct it piece by piece all by YOURSELF. The following code will produce something that is quite similar to what you will get from plot.xts (at least to me). There is no time series structure involved as I am not familiar with it. BTW, the "Canada" data is provided with vars package not with R base installation.
复制代码
Here I have mapped all the data into the range [0, 6] and the quarterly time to [0, 83]. The result follows:

plot_xts.png

I am sure there are simpler/better solutions. This just serves as an exmaple showing the super flexibility of R graphic.

I have not tried Rsweave but would probably expect little change in the codes. As far as I am aware of there is no limit on number of packages loaded in older version of R.

Here is my session info:
复制代码
Good luck.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-11-12 09:52:10
表示顶一下~如果能够帮助解答的可以再追加200论坛币~真的是急求~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-11-13 14:39:31
zhangyangsmith 发表于 2013-11-12 18:41
I have little knowledge on time series or ananlysis of economic data. But I am interested to do (all ...
Actually what you've posted is virtually the same with the one shown on the stackoverflow or other forums which I've seen before.

I knew the methodology and would take a try. But the major worry is that it is so delicate and arduous to calculate the distance in order to draw the scale of x or y axis. If you have an irregular time series data, it is really difficult and time-exhausted to do that. So that's the reason why I want to find other solutions beyond that and why I choose specific time series packages like xts to draw the time series plot....
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-8-6 22:24:42
不知道这么久过去了楼主解决了这个问题没有。
只要在plot中加上ylim=c(a,b)就可以。其中a b 是你想要的上下限。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群