'plot.ts: putting data in right order and adding labels
[image of current time series graph]
1This is my dataframe:
structure(list(MY = c("01 13", "01 14", "01 15", "01 16", "01 17", "01 18", "01 19", "01 20", "01 21", "02 12", "02 14", "02 15", "02 16", "02 17", "02 18", "02 19", "02 20", "02 21", "03 11", "03 12", "03 13", "03 14", "03 15", "03 16", "03 17", "03 18", "03 19", "03 20", "03 21", "04 10", "04 13", "04 15", "04 16", "04 17", "04 18", "04 19", "04 20", "04 21", "05 11", "05 13", "05 14", "05 15", "05 16", "05 17", "05 18", "05 19", "05 20", "05 21", "06 13", "06 14", "06 15", "06 16", "06 17", "06 18", "06 19", "06 20", "06 21", "07 13", "07 14", "07 15", "07 16", "07 17", "07 18", "07 19", "07 20", "07 21", "08 12", "08 13", "08 14", "08 15", "08 16", "08 17", "08 18", "08 19", "08 20", "08 21", "09 13", "09 14", "09 15", "09 16", "09 17", "09 18", "09 19", "09 20", "10 14", "10 15", "10 16", "10 17", "10 18", "10 19", "10 20", "11 11", "11 13", "11 14", "11 15", "11 16", "11 17", "11 18", "11 19", "11 20", "12 14", "12 15", "12 16", "12 17", "12 18", "12 19", "12 20"), n = c(1L, 2L, 12L, 100L, 359L, 79L, 69L, 188L, 132L, 1L, 2L, 9L, 97L, 230L, 76L, 78L, 188L, 127L, 1L, 2L, 8L, 4L, 21L, 120L, 156L, 76L, 76L, 159L, 170L, 1L, 120L, 50L, 180L, 109L, 149L, 47L, 49L, 88L, 3L, 19L, 1L, 43L, 212L, 103L, 210L, 67L, 29L, 151L, 7L, 4L, 43L, 142L, 86L, 289L, 41L, 57L, 402L, 1L, 11L, 83L, 113L, 98L, 116L, 96L, 64L, 263L, 1L, 3L, 13L, 68L, 134L, 75L, 94L, 86L, 72L, 156L, 3L, 3L, 88L, 144L, 129L, 113L, 125L, 77L, 9L, 75L, 162L, 124L, 90L, 103L, 99L, 1L, 1L, 3L, 91L, 232L, 102L, 70L, 51L, 118L, 4L, 72L, 208L, 5196L, 50L, 73L, 105L), percent = c(0.0068903741473162, 0.0137807482946324, 0.0826844897677944, 0.68903741473162, 2.47364431888652, 0.54433955763798, 0.475435816164818, 1.29539033969545, 0.909529387445738, 0.0068903741473162, 0.0137807482946324, 0.0620133673258458, 0.668366292289671, 1.58478605388273, 0.523668435196031, 0.537449183490664, 1.29539033969545, 0.875077516709157, 0.0068903741473162, 0.0137807482946324, 0.0551229931785296, 0.0275614965892648, 0.14469785709364, 0.826844897677944, 1.07489836698133, 0.523668435196031, 0.523668435196031, 1.09556948942328, 1.17136360504375, 0.0068903741473162, 0.826844897677944, 0.34451870736581, 1.24026734651692, 0.751050782057466, 1.02666574795011, 0.323847584923861, 0.337628333218494, 0.606352924963826, 0.0206711224419486, 0.130917108799008, 0.0068903741473162, 0.296286088334597, 1.46075931923103, 0.709708537173569, 1.4469785709364, 0.461655067870185, 0.19982085027217, 1.04044649624475, 0.0482326190312134, 0.0275614965892648, 0.296286088334597, 0.9784331289189, 0.592572176669193, 1.99131812857438, 0.282505340039964, 0.392751326397023, 2.76993040722111, 0.0068903741473162, 0.0757941156204782, 0.571901054227245, 0.77861227864673, 0.675256666436987, 0.799283401088679, 0.661475918142355, 0.440983945428237, 1.81216840074416, 0.0068903741473162, 0.0206711224419486, 0.0895748639151106, 0.468545442017502, 0.923310135740371, 0.516778061048715, 0.647695169847723, 0.592572176669193, 0.496106938606766, 1.07489836698133, 0.0206711224419486, 0.0206711224419486, 0.606352924963826, 0.992213877213533, 0.88885826500379, 0.77861227864673, 0.861296768414525, 0.530558809343347, 0.0620133673258458, 0.516778061048715, 1.11624061186522, 0.854406394267209, 0.620133673258458, 0.709708537173569, 0.682147040584304, 0.0068903741473162, 0.0068903741473162, 0.0206711224419486, 0.627024047405774, 1.59856680217736, 0.702818163026252, 0.482326190312134, 0.351409081513126, 0.813064149383312, 0.0275614965892648, 0.496106938606766, 1.43319782264177, 35.802384069455, 0.34451870736581, 0.502997312754083, 0.723489285468201)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -107L))
I would like to do a timetrend graph of my monthly data.The MY variable represents the month and year of the data e.g. 01 13, is Jan 2013. First of all, I would like the the MY to be in the right order, e.g. I want it to go like: 01 2011, 02 2011,03 2011....etc (I want all the months to be there even if n=0 for that month).
Then I want to plot it using plot(as.ts(s)), but I want the labels for each month to be in the x-axis. Right now my plot is not in the right order and there are no labels plot(as.ts(s))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
