简体   繁体   English

R中的时间序列图

[英]Timeseries plotting in R

I am plotting a time series data in R. In the X-axis I should get the year as 2014, 2015, 2016 where as I'm getting 2014.0, 2014.5, 2015.0, 2015.5, 2016.0 and 2016.5 which is very annoying. 我正在R中绘制时间序列数据。在X轴上,我应该将年份设为2014、2015、2016,而当我得到2014.0、2014.5、2015.0、2015.5、2016.0和2016.5时,这非常令人讨厌。 How can I get rid of this? 我该如何摆脱呢?

Below given is the code I have used. 下面给出的是我使用的代码。

inflow<-ts(inflow,start = c(2014,1),frequency = 12)
plot(inflow, xlab="Year", ylab="Inflow Count")

Can anyone please help me how should I get rid of the decimal part in the year field in X-axis. 谁能帮我摆脱X轴年份字段中的小数部分。 I am attaching the image ( R Plot ) with my resulting output as well. 我也将图像( R Plot )附加到我的结果输出中。

It depends on the input data or the way you want to plot your data. 这取决于输入数据或要绘制数据的方式。 Give following lines a try for your needs: 尝试以下几行以满足您的需求:

data(USAccDeaths) 
USAccDeaths
plot(USAccDeaths, type="l", pch=16, cex=1, col="#425a10",bty="l", xlab="Year",ylab="Accident Deaths", main="Accident Deaths USA 1973 - 1979")

The input data: 输入数据:

YEAR   Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
1973  9007  8106  8928  9137 10017 10826 11317 10744  9713  9938  9161  8927
1974  7750  6981  8038  8422  8714  9512 10120  9823  8743  9129  8710  8680
1975  8162  7306  8124  7870  9387  9556 10093  9620  8285  8466  8160  8034
1976  7717  7461  7767  7925  8623  8945 10078  9179  8037  8488  7874  8647
1977  7792  6957  7726  8106  8890  9299 10625  9302  8314  8850  8265  8796
1978  7836  6892  7791  8192  9115  9434 10484  9827  9110  9070  8633  9240

and the resulting plot: 和结果情节:

在此处输入图片说明

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

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