简体   繁体   中英

how to remove fractional value in x-axis of timeseries in R

I wanted to generate a timeseries with the following code:

Chlorophyll_data<-read.csv("Chlorophyll.csv", header = T)
#create a timeseries object which has built in functionality 
Chlorophyll.ts <- ts(Chlorophyll_data$Chlorophyll, frequency=12, start=c(2014,1)) 
plot.ts(Chlorophyll.ts, format = "%Y")
Chlorophyll.components <- decompose(Chlorophyll.ts)
plot(Chlorophyll.components, format="%Y")

The plot looks like this timeseries decomposition

But the x-axis of the plots shows a fractional value of years. Can someone please tell me how should I remove the fractional values?

My data is:

Year  Month Chlorophyll
2014    1   55.33462
2014    2   85.79968
2014    3   75.10592
2014    5   66.46263
2014    6   84.44795
2014    7   77.94365
2014    8   114.8308
2014    9   67.64554
2014    10  92.86682
2014    11  112.0653
2015    1   39.25982
2015    2   51.15999
2015    3   55.7578
2015    4   67.80606
2015    6   60.78814
2015    7   69.00764
2015    8   64.76438
2015    9   57.52195
2015    11  73.32797
2015    12  31.36951
2016    1   61.07596
2016    2   50.15889
2016    3   93.3778
2016    4   103.4554
2016    5   106.4145
2016    6   77.07053
2016    7   70.27304
2016    8   62.89573
2016    9   76.19891
2016    10  86.45399
2016    11  70.48216
2016    12  40.78854

Thanks.

One way to do this is simply leave off the x-axis and then put it on yourself using the axis function.

plot(Chlorophyll.components, xaxt="n")
axis(side=1, at=2014:2017, line=1.1)

手动轴

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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