Kaja Kaja - 2 months ago 17
R Question

define x-axe for time series data

I would like to plot time series data. I have generated my data with this code:

PlotDataKanada <- ts(SortDataKanada[SortDataKanada$`Influenza Season and Epidemiological Week`>=201101 & SortDataKanada$`Influenza Season and Epidemiological Week`<201401,]$TotalPatienten, frequency = 52, start = 2011, end = 2014)


and then plot it:

plot(PlotDataKanada,type="l",ylab="Number of Patients")


My data in
PlotDataKanada
:

Time Series:
Start = c(2011, 1)
End = c(2014, 1)
Frequency = 52
[1] 1323 1147 1145 1008 986 1034 958 816 789 692 499 427 406
[14] 374 306 183 162 109 71 41 32 8 2 3 2 1
[27] 2 3 2 2 2 2 NA 1 4 3 2 2 3
[40] 6 6 2 10 14 8 13 26 15 30 72 64 102
[53] 121 130 148 189 234 273 328 528 811 990 1128 1049 737
[66] 605 626 590 369 345 231 179 113 58 33 27 16 11
[79] 3 7 3 10 1 2 2 4 6 2 8 4 10
[92] 24 14 31 83 126 185 302 389 843 1611 2528 3217 3729
[105] 2832 1805 1203 940 747 576 518 525 486 449 388 398 340
[118] 393 347 309 260 182 95 61 31 16 1 7 28 7
[131] 6 14 14 12 38 39 57 122 100 165 229 443 787
[144] 1313 1323 1147 1145 1008 986 1034 958 816 789 692 499 427
[157] 406


enter image description here

on x-axis I see float values 2011.0,2011.5,...

But I would like to have only integer values: 2011,2012,...

How should I change my code?

J_F J_F
Answer

A very quick solution would be this:

plot(PlotDataKanada,type="l",ylab="Number of Patients", xaxt= "n")
axis(1, seq(2011,2014))