R: Separate data of an hts object - r

I've being playing with the hts package in order to forecast some products that are linked through different categories, it's a typical case where the data is something like:
Business Units (BU) => Category => Sub-Category => SKU
So far I've been able to create the hts object according to the needed hierarchy and also run some forecasts for all the aggregated data.
Since there are different BU's I want to run a different model for each BU, and also analyse the data for each BU separately. I know I can make an hts object for each BU and then use combinef to aggregate all the forecasts but I was wondering if it was possible to do it with just one hts object and some modified GmatrixH function.
To make it more graphically, lets assume I have something like this in my initial hts data:
=> A
=> A20
=> A201
=> A202
=> A30
=> A301
=> A302
=> B
=> B10
=> B101
=> B102
=> B20
=> B201
=> B202
My goal is to able to separate the data to just something like this:
=> A
=> A20
=> A201
=> A202
=> A30
=> A301
=> A302
Example code: Rather than use a different data set lets assume that htseg2 is the data, so, looking at the aggts of htseg2 we see:
all_y <- aggts(htseg2)
Time Series:
Start = 1992
End = 2007
Frequency = 1
Total A B A10 A20 B30 B40 A10A A10B A10C A20A A20B B30A B30B B40A
1992 -2.2112904 -5.103778 2.892488 -4.344453 -0.7593252 0.8077966 2.084691 -2.423474 -1.1620698 -0.7589091 -0.4983286 -0.26099657 0.009695794 0.3270945 0.4710063
1993 -1.7426751 -4.850060 3.107385 -4.103407 -0.7466530 0.8326560 2.274729 -2.196065 -1.1576038 -0.7497389 -0.4979251 -0.24872791 0.022737218 0.3358589 0.4740598
1994 -1.4533386 -4.688907 3.235569 -3.960646 -0.7282608 0.9080350 2.327534 -2.187683 -1.0524048 -0.7205582 -0.4954755 -0.23278530 0.064194769 0.3367939 0.5070464
1995 -1.0151533 -4.386465 3.371312 -3.695228 -0.6912372 0.9728715 2.398440 -1.932308 -1.0519018 -0.7110175 -0.4818329 -0.20940428 0.098071735 0.3611585 0.5136413
1996 -0.2687558 -3.947446 3.678690 -3.331862 -0.6155842 1.0763970 2.602293 -1.637783 -1.0139068 -0.6801723 -0.4253173 -0.19026691 0.146079487 0.3738506 0.5564668
1997 -0.1039130 -3.891031 3.787118 -3.284696 -0.6063356 1.1220049 2.665113 -1.627386 -0.9823162 -0.6749934 -0.4247379 -0.18159770 0.170240635 0.3890064 0.5627578
1998 0.0319309 -3.815398 3.847329 -3.219069 -0.5963289 1.1310482 2.716281 -1.614443 -0.9486647 -0.6559620 -0.4150329 -0.18129604 0.173920725 0.3916081 0.5655194
1999 0.2386283 -3.689795 3.928423 -3.125673 -0.5641226 1.1638044 2.764619 -1.590909 -0.8935917 -0.6411720 -0.3924141 -0.17170855 0.205094593 0.3931835 0.5655263
2000 0.4762250 -3.580883 4.057108 -3.036069 -0.5448139 1.2111129 2.845995 -1.532260 -0.8687816 -0.6350273 -0.3785346 -0.16627934 0.235250213 0.4085820 0.5672806
2001 0.7640473 -3.373380 4.137427 -2.877374 -0.4960051 1.2474490 2.889978 -1.390682 -0.8537141 -0.6329781 -0.3748754 -0.12112965 0.241523003 0.4140894 0.5918366
2002 0.9577465 -3.321418 4.279164 -2.836797 -0.4846210 1.2635735 3.015591 -1.367034 -0.8388968 -0.6308661 -0.3713899 -0.11323106 0.253885861 0.4170116 0.5926760
2003 1.1278373 -3.244452 4.372290 -2.786883 -0.4575690 1.3112792 3.061011 -1.334805 -0.8283677 -0.6237109 -0.3536588 -0.10391014 0.279924841 0.4247898 0.6065645
2004 1.3618556 -3.130861 4.492716 -2.715788 -0.4150729 1.3568514 3.135865 -1.318941 -0.8255442 -0.5713028 -0.3182323 -0.09684063 0.283730794 0.4450246 0.6280960
2005 1.7552645 -2.991873 4.747138 -2.615245 -0.3766279 1.3736268 3.373511 -1.242796 -0.8054984 -0.5669504 -0.3044265 -0.07220149 0.288582178 0.4568084 0.6282362
2006 2.0580599 -2.936933 4.994993 -2.582444 -0.3544895 1.4013893 3.593604 -1.240751 -0.7970741 -0.5446189 -0.3015478 -0.05294174 0.296206517 0.4598029 0.6453799
2007 2.3738339 -2.836078 5.209912 -2.511904 -0.3241741 1.4523193 3.757593 -1.220774 -0.7866848 -0.5044450 -0.2963444 -0.02782969 0.317670953 0.4671018 0.6675465
B40B B40C
1992 0.6941430 1.390548
1993 0.7440005 1.530729
1994 0.7800831 1.547451
1995 0.8195736 1.578866
1996 0.8798774 1.722416
1997 0.9265925 1.738521
1998 0.9710759 1.745205
1999 1.0151125 1.749507
2000 1.0558906 1.790104
2001 1.0990149 1.790963
2002 1.2131865 1.802404
2003 1.2471263 1.813884
2004 1.3140384 1.821827
2005 1.3778140 1.995697
2006 1.3785545 2.215049
2007 1.3875096 2.370083
If I do:
all_y_lA <- aggts(htseg2, levels=1)
I get:
Time Series:
Start = 1992
End = 2007
Frequency = 1
A B
1992 -5.103778 2.892488
1993 -4.850060 3.107385
1994 -4.688907 3.235569
1995 -4.386465 3.371312
1996 -3.947446 3.678690
1997 -3.891031 3.787118
1998 -3.815398 3.847329
1999 -3.689795 3.928423
2000 -3.580883 4.057108
2001 -3.373380 4.137427
2002 -3.321418 4.279164
2003 -3.244452 4.372290
2004 -3.130861 4.492716
2005 -2.991873 4.747138
2006 -2.936933 4.994993
2007 -2.836078 5.209912
And what I want is to do something like:
all_y_lA <- aggts(htseg2, levels="A")
And get:
A A10 A20 A10A A10B A10C A20A A20B
1992 -5.103778 -4.344453 -0.7593252 -2.423474 -1.1620698 -0.7589091 -0.4983286 -0.26099657
1993 -4.85006 -4.103407 -0.746653 -2.196065 -1.1576038 -0.7497389 -0.4979251 -0.24872791
1994 -4.688907 -3.960646 -0.7282608 -2.187683 -1.0524048 -0.7205582 -0.4954755 -0.2327853
1995 -4.386465 -3.695228 -0.6912372 -1.932308 -1.0519018 -0.7110175 -0.4818329 -0.20940428
1996 -3.947446 -3.331862 -0.6155842 -1.637783 -1.0139068 -0.6801723 -0.4253173 -0.19026691
1997 -3.891031 -3.284696 -0.6063356 -1.627386 -0.9823162 -0.6749934 -0.4247379 -0.1815977
1998 -3.815398 -3.219069 -0.5963289 -1.614443 -0.9486647 -0.655962 -0.4150329 -0.18129604
1999 -3.689795 -3.125673 -0.5641226 -1.590909 -0.8935917 -0.641172 -0.3924141 -0.17170855
2000 -3.580883 -3.036069 -0.5448139 -1.53226 -0.8687816 -0.6350273 -0.3785346 -0.16627934
2001 -3.37338 -2.877374 -0.4960051 -1.390682 -0.8537141 -0.6329781 -0.3748754 -0.12112965
2002 -3.321418 -2.836797 -0.484621 -1.367034 -0.8388968 -0.6308661 -0.3713899 -0.11323106
2003 -3.244452 -2.786883 -0.457569 -1.334805 -0.8283677 -0.6237109 -0.3536588 -0.10391014
2004 -3.130861 -2.715788 -0.4150729 -1.318941 -0.8255442 -0.5713028 -0.3182323 -0.09684063
2005 -2.991873 -2.615245 -0.3766279 -1.242796 -0.8054984 -0.5669504 -0.3044265 -0.07220149
2006 -2.936933 -2.582444 -0.3544895 -1.240751 -0.7970741 -0.5446189 -0.3015478 -0.05294174
2007 -2.836078 -2.511904 -0.3241741 -1.220774 -0.7866848 -0.504445 -0.2963444 -0.02782969
Then analyse and forecast A and all childs of A, and then the same for B.
Hope I make myself clear, thanks in advance for any help.

Related

Merge and update columns

I am trying to rebuild some MS Access update query logic with R's merge function, as the update query logic is missing a few arguments.
Table link Google drive
In my database "Invoice Account allocation", there are 2 tables:
Account_Mapping Table:
Origin Origin Postal Destination Destination Invoice
country code country postal code Account
FRA 01 GBR * ZR001
FRA 02 BEL * ZR003
BEL 50 ARG * ZR002
GER 01 ITA * ZR002
POL 02 ESP * ZR001
ESP 50 NED * ZR003
* 95 FRA 38 ZR001
BEL * * * ZR002
* * * * ZR003
FRA * FRA 25 ZR004
Load_ID
ID Origin Postal Destination Destination Default
country code postal code Invoice Account
2019SN0201948 FRA 98 FRA 38 XXAC001
2019SN0201958 POL 56 GBR 15 XXAC001
2019SN0201974 BEL 50 ARG 27 XXAC001
2019SN0201986 FRA 02 GER 01 XXAC001
The default invoice account in tables (Load_ID and Status_ID) is updated by the invoice account from the Account_Mapping table.
The tables Account_Mapping and Load_ID can be joined by:
Origin country & Origin country,
Origin Postal code & Postal code,
Destination country & Destination, and
Destination postal code & Destination postal code.
In the account_mapping table, there are several "*", it means the string value can take any value. I am not able build this logic with merge function. Please help me with a better logic.
New_Assigned_Account_Final <- merge(Load_ID, Account_Mapping, by.x =
c("Origin country","Postal code","Destination", "Destination postal code"),
by.y =
c("Origin country","Origin Postal code","Destination country", "Destination
postal code"))
Desired result:
Updated Load_ID table as below.
Load_ID:
ID Origin Postal Destination Destination Default
country code postal code Invoice Account
2019SN0201948 FRA 98 FRA 38 ZR003
2019SN0201958 POL 56 GBR 15 ZR003
2019SN0201974 BEL 50 ARG 27 ZR002
2019SN0201986 FRA 02 GER 01 ZR003
For the first ID, the default ID becomes "ZR003" because, "FRA" as Origin country doesn't have a Postal code - "98", so it falls under the all "*" bucket and is allocated to ZR003.
For the third ID, the default ID becomes "ZR002" because, "BEL" as Origin country has a Postal code - "50" associated with it, and the destination postal code of "ARG" can be anything because of the "*" in the Destination postal code column, therefore it is allocated to ZR002.
Thank you for your inputs.

SAS plot SGPLOT

I have 3 columns A, B, C. I tried to do a overlay plot, which shows one line of B and one line of C (A is the x axis). However, when I use the code below, the output looks super ugly. What is a better way to do it? Thank you.
proc plot data=djia;
plot A*B='*'
A*C='o' / overlay box;
title 'Plot of Highs and Lows';
title2 'for the Dow Jones Industrial Average';
run;
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473570.htm
In SGPLOT the plotting statements, by defaults, plot onto the same graphing 'canvas', and thus overlay. The first statements are drawn first, so you can produce any desired 'z-effect' for the overlaying.
Example plotting djia data.
proc sgplot data=djia;
band x=year lower=low upper=high / fillatrrs=(color=vlig);
series x=year y=high / markers;
series x=year y=low / markers;
run;
The SAS knowledge base article http://support.sas.com/kb/51/821.html shows how to band (fill) the region between low and high.
Data for example
* from http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000075748.htm#a000075747 ;
data djia;
input Year #7 HighDate date7. High #24 LowDate date7. Low;
format highdate lowdate date7.;
datalines;
1954 31DEC54 404.39 11JAN54 279.87
1955 30DEC55 488.40 17JAN55 388.20
1956 06APR56 521.05 23JAN56 462.35
1957 12JUL57 520.77 22OCT57 419.79
1958 31DEC58 583.65 25FEB58 436.89
1959 31DEC59 679.36 09FEB59 574.46
1960 05JAN60 685.47 25OCT60 568.05
1961 13DEC61 734.91 03JAN61 610.25
1962 03JAN62 726.01 26JUN62 535.76
1963 18DEC63 767.21 02JAN63 646.79
1964 18NOV64 891.71 02JAN64 768.08
1965 31DEC65 969.26 28JUN65 840.59
1966 09FEB66 995.15 07OCT66 744.32
1967 25SEP67 943.08 03JAN67 786.41
1968 03DEC68 985.21 21MAR68 825.13
1969 14MAY69 968.85 17DEC69 769.93
1970 29DEC70 842.00 06MAY70 631.16
1971 28APR71 950.82 23NOV71 797.97
1972 11DEC72 1036.27 26JAN72 889.15
1973 11JAN73 1051.70 05DEC73 788.31
1974 13MAR74 891.66 06DEC74 577.60
1975 15JUL75 881.81 02JAN75 632.04
1976 21SEP76 1014.79 02JAN76 858.71
1977 03JAN77 999.75 02NOV77 800.85
1978 08SEP78 907.74 28FEB78 742.12
1979 05OCT79 897.61 07NOV79 796.67
1980 20NOV80 1000.17 21APR80 759.13
1981 27APR81 1024.05 25SEP81 824.01
1982 27DEC82 1070.55 12AUG82 776.92
1983 29NOV83 1287.20 03JAN83 1027.04
1984 06JAN84 1286.64 24JUL84 1086.57
1985 16DEC85 1553.10 04JAN85 1184.96
1986 02DEC86 1955.57 22JAN86 1502.29
1987 25AUG87 2722.42 19OCT87 1738.74
1988 21OCT88 2183.50 20JAN88 1879.14
1989 09OCT89 2791.41 03JAN89 2144.64
1990 16JUL90 2999.75 11OCT90 2365.10
1991 31DEC91 3168.83 09JAN91 2470.30
1992 01JUN92 3413.21 09OCT92 3136.58
1993 29DEC93 3794.33 20JAN93 3241.95
1994 31JAN94 3978.36 04APR94 3593.35
;
In general in SGxxx procs you just add more statements to get more things to appear on the graph. For example you might want to show regression lines for AGE * WEIGHT and AGE * HEIGHT on the same graph.
proc sort data=sashelp.class out=class ;
by age;
run;
proc sgplot data=class;
reg x=age y=weight / legendlabel='Weight';
reg x=age y=height / legendlabel='Height' y2axis;
run;

Error: For weekly time series forecasting with tbats, highchart doesn't plot

x = apply.monthly(xts(data1$Sales,order.by = date1),FUN = sum)
x = as.data.frame(x)
x1 = ts(x,frequency = 12,start = c(2011,1),end = c(2014,12))
hchart(forecast(auto.arima(x1)))
So, Output of forecast is :
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 2015 358371.9 315315.3 401428.5 292522.5 424221.3
Feb 2015 323524.1 276176.7 370871.6 251112.4 395935.8
Mar 2015 381082.9 329802.3 432363.4 302656.1 459509.7
Apr 2015 362998.6 308065.9 417931.3 278986.3 447011.0
May 2015 415109.8 356753.0 473466.6 325860.8 504358.8
Jun 2015 509654.5 448063.7 571245.3 415459.5 603849.5
Jul 2015 377217.7 312554.5 441881.0 278323.9 476111.6
Aug 2015 517245.5 449649.3 584841.6 413866.0 620624.9
Sep 2015 552086.9 481679.9 622494.0 444408.6 659765.2
Oct 2015 485304.4 412194.4 558414.3 373492.4 597116.4
Nov 2015 583234.5 507518.1 658950.9 467436.3 699032.8
Dec 2015 586645.4 508409.3 664881.5 466993.6 706297.1
Jan 2016 424985.8 340008.8 509962.7 295024.7 554946.8
Feb 2016 390138.0 301632.4 478643.7 254780.3 525495.7
Mar 2016 447696.7 355797.8 539595.7 307149.4 588244.0
Apr 2016 429612.5 334441.2 524783.8 284060.5 575164.5
May 2016 481723.7 383388.8 580058.6 331333.5 632113.9
Jun 2016 576268.4 474868.6 677668.2 421190.8 731346.0
Jul 2016 443831.6 339456.9 548206.3 284204.3 603459.0
Aug 2016 583859.3 476592.2 691126.5 419808.3 747910.3
Sep 2016 618700.8 508617.1 728784.5 450342.4 787059.3
Oct 2016 551918.3 439088.4 664748.1 379359.8 724476.7
Nov 2016 649848.4 534337.6 765359.2 473189.9 826507.0
Dec 2016 653259.3 535128.3 771390.2 472593.6 833924.9
So, for above data highchart is working properly, but when I tried it for weekly data with TBATS function, it gives something like below,
x1 = ts(x,freq = 365.25/7,start = 2011+31/365.25)
bestfit <- list(aicc=Inf)
fitmodel <- tbats(x1)
forecastweekly <- forecast(fitmodel, h=200)
and forecast output is :
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2015.110 77239.91 62831.38 91648.44 55203.96 99275.86
2015.129 71852.27 57413.72 86290.82 49770.41 93934.13
2015.148 71560.14 57042.50 86077.79 49357.32 93762.96
2015.167 73289.48 58602.92 87976.04 50828.33 95750.64
2015.186 73652.31 58732.79 88571.84 50834.87 96469.76
2015.205 71700.22 56559.47 86840.98 48544.43 94856.02
2015.225 69387.13 54075.57 84698.69 45970.11 92804.14
2015.244 69554.04 54104.26 85003.83 45925.64 93182.45
2015.263 73306.79 57716.77 88896.82 49463.91 97149.68
2015.282 78975.88 63224.05 94727.71 54885.53 103066.23
2015.301 83368.51 67442.71 99294.31 59012.10 107724.93
2015.320 84148.31 68060.33 100236.30 59543.86 108752.76
2015.339 81426.24 65196.75 97655.74 56605.37 106247.11
2015.359 77443.50 61081.10 93805.90 52419.37 102467.63
2015.378 74775.69 58272.42 91278.97 49536.12 100015.27
2015.397 74558.00 57901.69 91214.32 49084.37 100031.64
2015.416 76095.25 59285.54 92904.96 50387.01 101803.48
2015.435 78060.88 61110.28 95011.48 52137.18 103984.59
2015.454 80180.84 63100.97 97260.72 54059.43 106302.25
2015.474 83822.54 66613.41 101031.67 57503.44 110141.64
2015.493 90712.50 73365.03 108059.98 64181.84 117243.17
2015.512 100614.62 83122.87 118106.38 73863.30 127365.95
2015.531 109996.21 92365.73 127626.69 83032.72 136959.70
2015.550 113344.54 95586.69 131102.39 86186.25 140502.83
2015.569 106822.66 88942.86 124702.47 79477.86 134167.47
2015.589 91762.34 73755.78 109768.90 64223.68 119301.00
2015.608 75016.97 56875.59 93158.36 47272.12 102761.83
2015.627 65240.68 46964.00 83517.37 37288.90 93192.47
2015.646 67389.62 48986.56 85792.69 39244.57 95534.68
2015.665 79501.06 60980.53 98021.58 51176.36 107825.75
2015.684 94341.82 75703.92 112979.72 65837.61 122846.03
2015.704 104738.56 85975.61 123501.51 76043.10 133434.01
2015.723 108388.65 89495.21 127282.10 79493.63 137283.68
2015.742 108375.06 89355.88 127394.24 79287.74 137462.38
2015.761 109260.33 90126.03 128394.63 79996.94 138523.71
2015.780 112408.56 93164.45 131652.67 82977.23 141839.89
2015.799 114746.16 95387.18 134105.13 85139.16 144353.16
2015.819 111991.74 92508.83 131474.64 82195.20 141788.27
2015.838 103303.51 83695.64 122911.38 73315.86 133291.16
2015.857 92995.07 73272.48 112717.66 62831.97 123158.17
2015.876 87624.60 67798.21 107450.99 57302.76 117946.44
2015.895 90935.62 71005.54 110865.70 60455.19 121416.04
2015.914 101024.88 80980.22 121069.54 70369.21 131680.54
2015.934 112068.57 91900.42 132236.72 81224.05 142913.10
2015.953 118900.25 98615.37 139185.12 87877.21 149923.29
2015.972 120396.94 100013.10 140780.77 89222.55 151571.32
2015.991 119001.71 98529.05 139474.37 87691.47 150311.95
2016.010 117346.47 96775.77 137917.18 85886.30 148806.65
2016.029 115418.48 94727.90 136109.06 83774.97 147061.99
2016.049 110873.10 90056.68 131689.51 79037.14 142709.05
2016.068 101934.77 81024.78 122844.76 69955.70 133913.84
2016.087 89905.85 68950.05 110861.65 57856.72 121954.98
2016.106 78799.43 57824.70 99774.16 46721.35 110877.51
2016.125 72389.82 51396.94 93382.69 40283.98 104495.65
2016.144 71351.98 50313.37 92390.59 39176.20 103527.76
2016.164 73003.82 51860.00 94147.65 40667.13 105340.51
2016.183 73773.35 52471.74 95074.96 41195.35 106351.36
2016.202 72159.45 50697.92 93620.97 39336.88 104982.02
2016.221 69690.29 48101.92 91278.66 36673.73 102706.85
2016.240 69256.12 47567.38 90944.87 36086.05 102426.20
2016.259 72415.52 50628.61 94202.44 39095.31 105735.74
2016.279 77962.67 56062.75 99862.59 44469.63 111455.71
2016.298 82809.41 60784.56 104834.26 49125.31 116493.51
2016.317 84304.26 62159.57 106448.94 50436.88 118171.63
2016.336 82086.07 59836.17 104335.97 48057.78 116114.36
2016.355 78121.18 55774.15 100468.21 43944.35 112298.01
2016.374 75078.43 52629.85 97527.01 40746.29 109410.57
2016.394 74429.74 51869.81 96989.66 39927.31 108932.17
2016.413 75756.42 53082.36 98430.48 41079.43 110433.41
2016.432 77713.76 54933.27 100494.26 42874.00 112553.53
2016.451 79746.92 56869.18 102624.66 44758.44 114735.40
2016.470 82971.40 59997.81 105944.99 47836.33 118106.47
2016.489 89212.90 66136.98 112288.81 53921.33 124504.46
2016.509 98741.12 75556.92 121925.32 63283.95 134198.29
2016.528 108602.08 85311.87 131892.29 72982.78 144221.39
2016.547 113413.17 90025.09 136801.25 77644.19 149182.15
2016.566 108734.00 85253.17 132214.84 72823.16 144644.85
2016.585 94827.00 71250.69 118403.30 58770.15 130883.84
2016.604 77727.28 54048.85 101405.70 41514.25 113940.30
2016.624 66170.44 42387.77 89953.11 29797.98 102542.90
2016.643 66126.31 42245.02 90007.61 29603.02 102649.60
2016.662 76895.42 52922.76 100868.09 40232.39 113558.45
2016.681 91855.81 67793.01 115918.60 55054.94 128656.67
2016.700 103392.61 79234.14 127551.07 66445.42 140339.79
2016.719 108144.16 83884.58 132403.74 71042.33 145245.99
2016.739 108422.65 84063.92 132781.39 71169.18 145676.13
2016.758 108911.01 84460.96 133361.05 71517.89 146304.12
2016.777 111773.52 87237.39 136309.66 74248.74 149298.30
2016.796 114600.56 89975.52 139225.60 76939.81 152261.31
2016.815 112965.28 88243.86 137686.70 75157.14 150773.43
2016.834 105155.15 80334.64 129975.66 67195.46 143114.84
2016.854 94653.85 69740.89 119566.80 56552.78 132754.92
2016.873 87985.16 62988.95 112981.38 49756.75 126213.58
2016.892 89719.06 64641.36 114796.75 51366.03 128072.08
2016.911 98965.92 73798.98 124132.85 60476.41 137455.42
2016.930 110299.28 85034.53 135564.04 71660.17 148938.39
2016.949 118099.93 92740.04 143459.82 79315.33 156884.53
2016.969 120437.17 94995.61 145878.74 81527.65 159346.69
2016.988 119320.41 93807.25 144833.57 80301.40 158339.42
2017.007 117619.63 92030.25 143209.00 78484.06 156755.19
2017.026 115874.87 90192.15 141557.58 76596.54 155153.19
2017.045 111987.83 86202.47 137773.20 72552.52 151423.15
2017.064 103841.95 77974.49 129709.41 64281.08 143402.82
2017.084 92119.32 66208.61 118030.03 52492.32 131746.33
So, for above forecasted output, highchart function not works properly, e.g.:
hchart(forecastweekly)
It gives error as:
Error in as.Date.ts(.) : unable to convert ts time to Date class
but when I use plot function, it gives proper output. How can I deal with this error?
Here you can see a reproducible example taken from Rob J. Hyndman's website
library(forecast)
gas <- ts(read.csv("http://robjhyndman.com/data/gasoline.csv", header=FALSE)
[,1], freq=365.25/7, start=1991+31/365.25)
gastbats <- tbats(gas)
fc2 <- forecast(gastbats, h=104)
plot(fc2) #It works
hchart(fc2) #It doesn't
Regards!

"Residual" data after filter?

I have some data on UFO sightings
Date,Country,City,State,lat,lng
12/21/2016,USA,Waynesboro,VA,38.0652286,-78.90588756
12/21/2016,USA,Louisville,KY,38.2542376,-85.7594069
12/20/2016,USA,Santa Rosa,CA,38.4404675,-122.7144313
12/20/2016,USA,Fresno,CA,36.7295295,-119.7088612
12/19/2016,USA,Reymert,AZ,33.2297793,-111.2092898
12/19/2016,USA,Redding,CA,40.5863563,-122.3916753
12/19/2016,USA,Gilbert,AZ,33.294207,-111.7379465
12/19/2016,USA,Phoenix,AZ,33.4485866,-112.0773455
12/19/2016,USA,Huber Heights,OH,39.85902405,-84.11136285
12/19/2016,USA,Conway,AR,35.0886963,-92.442101
12/19/2016,USA,Anchorage,AK,61.2163129,-149.8948522
12/19/2016,USA,Town and Country,MO,38.6122751,-90.4634531
12/19/2016,USA,Salt Lake City,UT,40.7670126,-111.8904307
12/19/2016,USA,Richardson,TX,32.9481789,-96.7297205
12/18/2016,CANADA,Wetaskiwin,AB,52.968492,-113.3679199
12/18/2016,USA,Berryville,AR,36.364792,-93.5679666
12/18/2016,USA,Honolulu,HI,21.304547,-157.8556763
12/18/2016,USA,St. George,UT,37.104153,-113.5841312
12/18/2016,USA,Bend,OR,44.0581728,-121.3153095
12/18/2016,USA,Mission,KS,39.0277832,-94.6557913
12/18/2016,USA,Lancaster,OH,39.7136754,-82.5993293
12/17/2016,USA,San Pedro,CA,33.7358518,-118.2922933
12/17/2016,USA,Kahana,HI,21.5543942,-157.873405
12/17/2016,USA,San Diego,CA,32.7174209,-117.1627713
12/17/2016,USA,Waipio,HI,21.4172766,-157.9986758
12/17/2016,USA,Ojai,CA,34.4480495,-119.2428889
12/17/2016,USA,Weston,FL,26.103632,-80.40310188
12/17/2016,USA,Fairfield,CA,38.2493581,-122.0399662
12/16/2016,USA,Rio Rancho,NM,35.269381,-106.6328189
12/16/2016,USA,Hixson,TN,35.236207,-85.2982059
12/16/2016,USA,Dade City,FL,28.3647248,-82.1959177
12/16/2016,USA,La Veta,CO,37.5050118,-105.0077746
12/16/2016,USA,Kelso,WA,46.1420334,-122.9060317
12/16/2016,USA,Skiatook,OK,36.3684245,-96.0013846
12/16/2016,USA,Carson City,NV,39.1637984,-119.7674033
12/15/2016,USA,Syracuse,NY,43.0481221,-76.1474243
12/15/2016,USA,Johnson City,TN,36.3134398,-82.3534727
12/15/2016,USA,Davie,FL,26.075729,-80.28410888
12/15/2016,USA,Winchester,KS,39.3222209,-95.2669154
12/15/2016,USA,Middlefield,CT,41.717613,-81.2086884
12/15/2016,USA,Corbin,KY,36.9486986,-84.096876
12/15/2016,USA,Simpsonville,SC,34.7370639,-82.2542833
12/15/2016,USA,Panama City,FL,30.165156,-85.6605594
12/15/2016,USA,Chandler,AZ,33.3067132,-111.8408488
12/15/2016,USA,Ozark,AL,33.547741,-86.5591659
12/14/2016,USA,Cumming,GA,34.2073196,-84.1401925
12/14/2016,USA,North Chesterfield,VA,38.6560565,-90.5742028
12/14/2016,USA,Dabney,KY,37.1839682,-84.5499416
12/14/2016,USA,Clinton,CT,42.26306,-71.8052219
12/14/2016,USA,San Diego,CA,32.7174209,-117.1627713
12/14/2016,USA,South Burlington,VT,44.4669941,-73.1709603
12/14/2016,USA,Prescott Valley,AZ,34.6100243,-112.3157209
12/14/2016,USA,Monroe Twp,NJ,40.3183284,-74.42021822
12/14/2016,USA,Berthoud,CO,40.3083174,-105.0810923
12/13/2016,USA,Liberty Lake,WA,47.6631371,-117.0855724
12/13/2016,USA,Chicago,IL,41.8755546,-87.6244211
12/13/2016,USA,La Jolla,CA,32.8472711,-117.2742085
12/13/2016,USA,Fort Lauderdale,FL,26.1254381,-80.1381514
12/13/2016,USA,Cedar Rapids,IA,41.9758872,-91.6704052
12/13/2016,USA,Panama City,FL,30.165156,-85.6605594
12/13/2016,USA,Hale,MI,44.3777947,-83.8047086
12/13/2016,USA,Dubuque,IA,42.5006217,-90.6647966
12/13/2016,USA,St. Johns,FL,29.9032284,-81.4145467
12/13/2016,USA,West Des Moines,IA,41.5645337,-93.759528
12/13/2016,USA,Pasadena,CA,34.1476452,-118.1444778
12/12/2016,USA,Hagerstown,MD,39.6419219,-77.720264
12/12/2016,USA,Jacksonville,FL,30.3321838,-81.6556509
12/12/2016,USA,Taos,NM,36.4072485,-105.5730664
12/12/2016,USA,Stevens Pass,WA,47.7456352,-121.0891717
12/12/2016,USA,Marietta,GA,33.9528472,-84.5496147
12/12/2016,USA,West Collingswood,NJ,39.9062242,-75.0929516
12/12/2016,USA,South Lake Tahoe,CA,38.929125,-119.9878464
12/12/2016,USA,Salem,OR,44.9391565,-123.0331209
12/12/2016,USA,Eden Prairie,MN,44.8454356,-93.5297242
12/12/2016,USA,Smithville,MO,39.3869442,-94.5810658
11/12/2016,USA,Casey,IA,41.5049873,-94.5194148
11/12/2016,USA,St. George,UT,37.104153,-113.5841312
11/12/2016,USA,Fort Collins,CO,40.5508527,-105.0668084
11/12/2016,USA,Helena,MT,46.5927122,-112.0361089
11/12/2016,USA,Independence,LA,37.2242358,-95.708313
11/12/2016,USA,Chester,PA,39.849557,-75.3557457
11/12/2016,USA,Trabuco Canyon,CA,33.6626232,-117.5893799
11/12/2016,USA,Gallatin Gateway,MT,45.5915958,-111.1977303
10/12/2016,USA,Hot Springs,SD,43.431646,-103.4743629
10/12/2016,USA,Erving,MA,42.6000863,-72.3981415
10/12/2016,USA,Farragut,TN,35.8845238,-84.153526
10/12/2016,USA,Delta,CO,38.8368777,-107.8568293
10/12/2016,USA,Virginia Beach,VA,36.8529841,-75.9774182
10/12/2016,USA,Kayenta,AZ,36.717954,-110.2606012
10/12/2016,USA,Lahaina,HI,20.872684,-156.6762728
10/12/2016,USA,Navajo,NM,35.9040858,-109.0335346
10/12/2016,USA,Santa Fe,NM,35.6869996,-105.9377996
10/12/2016,USA,Arlington,VA,38.8903961,-77.0841584
10/12/2016,USA,Hickory,NC,35.7331895,-81.3412005
10/12/2016,USA,Pearland,TX,29.5639758,-95.2864298
9/12/2016,USA,Phoenix,AZ,33.4485866,-112.0773455
9/12/2016,USA,Portland,OR,45.5202471,-122.6741948
9/12/2016,USA,Oldsmar,FL,28.06906015,-82.6501914
9/12/2016,USA,Kingman,AZ,35.189443,-114.0530064
9/12/2016,USA,Fredericksburg,VA,38.3031837,-77.4605398
9/12/2016,USA,Lancing,TN,36.1206306,-84.6538307
9/12/2016,USA,Tewksbury,MA,42.6106479,-71.2342247
9/12/2016,USA,Newport,ME,44.8353424,-69.2739364
9/12/2016,CANADA,Truro,NS,45.366668,-63.3000059
8/12/2016,USA,Jerseyville,IL,39.1200471,-90.3284478
8/12/2016,USA,St. Clair,MO,38.0592942,-93.7945455
8/12/2016,USA,Cromwell,CT,41.2861336,-72.3557585
8/12/2016,USA,Atlanta,GA,33.7490987,-84.3901848
7/12/2016,USA,Saint Augustine,FL,29.8946952,-81.3145394
7/12/2016,USA,Anchorage,AK,61.2163129,-149.8948522
7/12/2016,USA,Napili,HI,20.9717546,-156.6756045
7/12/2016,USA,Bellingham,WA,48.754402,-122.4788601
7/12/2016,USA,Snellville,GA,33.857328,-84.0199107
7/12/2016,USA,Las Vegas,NV,36.1662859,-115.1492249
7/12/2016,USA,Riverdale,GA,33.5726113,-84.4132593
7/12/2016,USA,Plymouth,MA,41.9584367,-70.6672576
7/12/2016,USA,Orlando,FL,28.5479786,-81.4127841
6/12/2016,USA,High Point,NC,35.9556924,-80.0053175
6/12/2016,USA,Austin,NV,39.4932592,-117.0695385
6/12/2016,USA,Austin,NV,39.4932592,-117.0695385
6/12/2016,USA,Nairn,LA,29.4279955,-89.6108946
6/12/2016,USA,Holland,PA,40.1728871,-74.9926687
6/12/2016,USA,Manhattan,NY,40.7902778,-73.9597221
6/12/2016,USA,Lake Jackson,TX,29.0338575,-95.4343858
6/12/2016,USA,Union,IL,37.4616454,-89.2504792
6/12/2016,USA,Osterville,MA,41.6293398,-70.3866805
6/12/2016,USA,Sunrise,FL,26.1482449,-80.3288858
5/12/2016,CANADA,Regina,SK,50.4480951,-104.615818
5/12/2016,USA,Niantic,CT,32.7809195,-117.2524695
5/12/2016,USA,Ivins,UT,37.1685907,-113.6794056
5/12/2016,USA,Haskell,NJ,41.0284304,-74.2959822
5/12/2016,USA,Westmoreland,NH,42.9620253,-72.4423101
5/12/2016,CANADA,Keswick,ON,44.2278666,-79.46145
5/12/2016,USA,Elizabethtown,PA,40.153364,-76.604252
5/12/2016,USA,Webster,NY,43.2122851,-77.4299938
5/12/2016,USA,Stratford,CT,37.2584705,-79.9622598
5/12/2016,USA,La Pine,OR,43.6703995,-121.5036359
4/12/2016,USA,Sauk Rapids,MN,45.5919097,-94.166101
4/12/2016,USA,Huntington Beach,CA,33.6783336,-118.0000165
4/12/2016,USA,Freeport,ME,43.857307,-70.1037599
4/12/2016,USA,Sioux Falls,SD,43.5499749,-96.7003269
4/12/2016,USA,Arcade,GA,34.0778881,-83.5615535
4/12/2016,USA,Redwood Falls,MN,44.5393721,-95.1164477
4/12/2016,USA,Brinklow,MD,39.1659403,-77.0155329
4/12/2016,USA,Winter Harbor,ME,44.395523,-68.0836489
4/12/2016,USA,Severn,MD,39.127886,-76.6869129
4/12/2016,USA,Mission Viejo,CA,33.5965685,-117.6594049
4/12/2016,USA,Marana,AZ,32.4446988,-111.215709
4/12/2016,CANADA,London,ON,42.988576,-81.2466429
3/12/2016,USA,Matawan,NJ,40.41483,-74.229589
3/12/2016,USA,Morgantown,WV,39.6296809,-79.9559436
3/12/2016,USA,Corte Madera,CA,37.9254806,-122.5274754
3/12/2016,USA,Boone Grove,IN,41.3547602,-87.1294741
3/12/2016,USA,Rockville,MD,39.0840054,-77.1527572
3/12/2016,USA,North Snohomish,WA,47.9394115,-122.0779886
3/12/2016,USA,Whittier,CA,33.9748932,-118.0336974
3/12/2016,USA,Santa Cruz,CA,36.9735903,-122.0260569
3/12/2016,USA,Gorham,ME,43.6796943,-70.4429341
2/12/2016,USA,Philadelphia,PA,39.9523993,-75.1635898
2/12/2016,USA,Reidsville,NC,36.354859,-79.6644749
2/12/2016,USA,Raphine,VA,37.9373548,-79.2328101
2/12/2016,USA,Chester,VA,37.3569086,-77.4421817
2/12/2016,USA,Ashland,VA,37.7594012,-77.4806602
2/12/2016,USA,Snellville,GA,33.857328,-84.0199107
1/12/2016,USA,Plainville,CT,41.6745432,-72.8581557
1/12/2016,USA,Portland,TN,36.5817089,-86.5163832
1/12/2016,USA,Glendale,AZ,33.5389854,-112.1858156
1/12/2016,USA,Conway,SC,33.8360035,-79.0478142
1/12/2016,USA,San Bernardino,CA,34.1083449,-117.2897651
1/12/2016,USA,Amherst,NY,42.9783924,-78.7997615
1/12/2016,USA,Montgomery,AL,40.854156,-78.2711029
1/12/2016,USA,Asbury Park,NJ,40.2203907,-74.0120816
11/30/2016,USA,Edmonds,WA,47.8105738,-122.3774951
11/30/2016,USA,Camp Shelby,MS,31.1975317,-89.2078257
11/30/2016,USA,Riverton,WY,38.515529,-121.5321489
11/30/2016,USA,Radcliff,KY,37.8403456,-85.9491297
11/30/2016,USA,Kingsland,GA,30.7999563,-81.689826
11/30/2016,USA,Fayetteville,TX,29.9057817,-96.6727527
11/29/2016,USA,Belmont,MI,40.0057737,-81.0097515
11/29/2016,USA,Bridgeport,WV,39.2864787,-80.256198
11/29/2016,USA,American Canyon,CA,38.223457,-122.227043
11/29/2016,USA,Colorado Springs,CO,38.8339578,-104.8253484
11/29/2016,CANADA,Niagara Falls,ON,43.1089442,-79.0636192
11/29/2016,USA,Carlinville,IL,39.2797699,-89.8817661
11/29/2016,USA,Fairfield,CA,38.2493581,-122.0399662
11/29/2016,USA,Englewood,CO,39.6482059,-104.987964
11/29/2016,USA,Corona,CA,37.0066161,-121.9969062
11/29/2016,USA,Midland,MI,43.6155825,-84.2472116
11/29/2016,USA,Janesville,WI,42.7151854,-88.9907742
11/29/2016,USA,Plainfield,IL,41.623191,-88.2284325
11/29/2016,USA,Happy Valley,OR,43.1358923,-122.3804695
11/29/2016,USA,Anchor Point,AK,59.76826,-151.6775519
11/29/2016,USA,Fishers,IN,39.9555928,-86.0138728
11/28/2016,USA,Sutherlin,OR,43.3896628,-123.3123597
11/28/2016,USA,Tazewell,VA,37.1236041,-81.5684128
11/28/2016,USA,Athol,MA,42.5959203,-72.2267496
11/28/2016,USA,American Canyon,CA,38.223457,-122.227043
11/28/2016,USA,Ste. Genevieve,MO,37.9814415,-90.0417789
11/28/2016,USA,St. Petersburg,FL,27.77330515,-82.6469933
11/28/2016,USA,Waynesville,MO,37.8286516,-92.2007226
11/28/2016,USA,Seekonk,RI,41.8674548,-71.3797769
11/28/2016,USA,Vineland,NJ,39.473152,-75.0020264
11/28/2016,USA,Fairfield,ME,44.588511,-69.5990749
11/28/2016,USA,Athens,GA,33.94385375,-83.3972898
11/28/2016,USA,Centerville,IL,31.2579584,-95.9782919
11/28/2016,USA,Mooresville,NC,35.5848596,-80.8100723
11/28/2016,USA,Grand Junction,CO,39.063956,-108.5507316
11/27/2016,CANADA,Carrying Place,ON,43.8088119,-79.2334018
11/27/2016,USA,St. Petersburg,FL,27.77330515,-82.6469933
11/27/2016,USA,Bay Shore,NY,40.7250986,-73.2453945
11/27/2016,USA,Longmont,CO,40.1672117,-105.1019286
11/27/2016,USA,Kenmore,WA,47.7573202,-122.2440147
11/27/2016,USA,Maui,HI,20.8029568,-156.3106832
11/27/2016,USA,Allentown,PA,40.6022059,-75.4712793
11/27/2016,USA,Lake Charles,LA,30.2265949,-93.2173758
11/27/2016,USA,Raymond,NE,40.956282,-96.7834109
11/26/2016,USA,Bailey,CO,34.0349194,-102.8149371
11/26/2016,USA,Bergen,NY,43.085391,-77.9417139
11/26/2016,USA,Middletown,NY,41.4459271,-74.422934
11/26/2016,USA,Charlotte,NC,35.2270869,-80.8431267
11/26/2016,USA,Davenport,FL,28.1614046,-81.6017416
11/26/2016,USA,Allen Park,MI,42.2575385,-83.2110374
11/26/2016,USA,Naugatuck,CT,41.4860186,-73.0509431
11/26/2016,USA,Venice,FL,27.0998708,-82.4544131
11/26/2016,USA,Fairview,OR,45.5469302,-122.4370392
11/26/2016,USA,McDonough,GA,33.4473361,-84.1468615
11/26/2016,USA,Spearfish,SD,44.490817,-103.8593699
11/26/2016,USA,Shallotte,NC,33.9732275,-78.385837
11/26/2016,USA,Brooklyn,NY,40.64530975,-73.9550229
11/26/2016,USA,McChord AFB,WA,47.1377,-122.4764999
11/26/2016,USA,Vacaville,CA,38.3565773,-121.9877443
11/26/2016,USA,West New York,NJ,40.785529,-74.0083002
11/25/2016,USA,Olathe,KS,38.8843867,-94.8161126
11/25/2016,USA,Tyrone,GA,33.6723506,-82.8612562
11/25/2016,USA,Vero Beach,FL,27.6387163,-80.3975398
11/25/2016,USA,Bedford,IN,38.8611619,-86.4872148
11/25/2016,USA,Nevada,NV,39.5158825,-116.8537226
11/25/2016,USA,Brandon,FL,27.928464,-82.2880445
11/25/2016,USA,Port Orange,FL,29.10150985,-81.0105537
11/25/2016,USA,Torrance,CA,33.8358492,-118.3406287
11/25/2016,USA,Longmont,CO,40.1672117,-105.1019286
11/25/2016,USA,Corpus Christi,TX,27.8002542,-97.3955743
11/25/2016,USA,Warner Robins,GA,32.598313,-83.6256769
11/25/2016,USA,Newcastle,WA,47.5395736,-122.156333
11/24/2016,USA,Graham,NC,36.069026,-79.4005759
11/24/2016,USA,Annapolis,MD,38.9786401,-76.4927859
11/24/2016,USA,Balko,OK,36.6600752,-100.679207
11/24/2016,USA,Largo,FL,27.9094665,-82.7873243
11/24/2016,USA,Woodbridge,NJ,40.55418,-74.2860007
11/24/2016,USA,Woodbridge,NJ,40.55418,-74.2860007
11/24/2016,USA,Oldsmar,FL,28.06906015,-82.6501914
11/24/2016,USA,Zebulon,NC,35.824321,-78.3147199
11/24/2016,USA,Monrovia,MD,39.3720477,-77.2719278
11/24/2016,USA,Grand Junction,CO,39.063956,-108.5507316
11/24/2016,USA,Colorado Springs,CO,38.8339578,-104.8253484
11/24/2016,USA,D'iberville,MS,30.4263092,-88.8908637
11/23/2016,USA,Tinton Falls,NJ,40.3159438,-74.0851403
11/23/2016,USA,Beaverton,OR,45.4871723,-122.8037803
11/23/2016,USA,Central Square,NY,43.286736,-76.1460359
11/23/2016,USA,Carlsbad,CA,33.1580933,-117.3505938
11/23/2016,USA,Poteau,OK,35.0537094,-94.6235578
11/22/2016,USA,Mesa,AZ,33.436188,-111.5860661
11/22/2016,CANADA,Oshawa,ON,43.9172764,-78.8614873
11/22/2016,USA,Largo,FL,27.9094665,-82.7873243
11/22/2016,USA,Beecher,IL,41.34059,-87.6214285
11/22/2016,USA,Santa Clara,UT,37.1330355,-113.6541265
11/22/2016,USA,Santa Clara,UT,37.1330355,-113.6541265
11/22/2016,USA,Derby,KS,37.5455735,-97.268933
11/22/2016,USA,Cecil,PA,32.3026416,-86.0085693
11/22/2016,USA,Atkinson,NH,42.8384221,-71.1470036
11/22/2016,USA,Brooklyn,NY,40.64530975,-73.9550229
11/22/2016,USA,Floral City,FL,28.7211775,-82.3076844
11/22/2016,USA,Jarrettsville,MD,39.60455,-76.4777421
11/22/2016,USA,Gainesville,GA,34.2978794,-83.8240662
11/22/2016,USA,San Diego,CA,32.7174209,-117.1627713
11/22/2016,USA,Scarborough,ME,43.59622635,-70.3300556
11/22/2016,USA,Bismarck,ND,46.8083268,-100.7837391
11/21/2016,USA,Key Colony Beach,FL,24.7209744,-81.0186826
11/21/2016,CANADA,Victoria,BC,48.4283327,-123.3649268
11/21/2016,USA,Riverdale,GA,33.5726113,-84.4132593
11/21/2016,USA,Fountain Hill,AR,33.3578937,-91.8504083
11/21/2016,USA,Ventura,CA,34.364744,-119.3105822
11/21/2016,USA,Alexandria,VA,33.7237617,-116.2673236
11/21/2016,USA,Pearisburg,VA,37.3265112,-80.7350711
11/21/2016,USA,Miramar Beach,FL,30.38208845,-86.3640414
11/21/2016,USA,Honolulu,HI,21.304547,-157.8556763
11/21/2016,USA,Sherman Oaks,CA,34.1508718,-118.4489864
11/21/2016,USA,Burbank,CA,34.1816482,-118.3258553
11/20/2016,USA,McKinney,TX,33.1976496,-96.615447
11/20/2016,USA,Boise,ID,43.61656,-116.2008349
11/20/2016,USA,Springfield,IL,39.7989763,-89.6443687
11/20/2016,USA,San Jose,CA,37.3361905,-121.8905832
11/20/2016,USA,Charleston,TN,35.4959148,-89.5089637
11/20/2016,USA,Lincoln,NE,40.8,-96.6678209
11/20/2016,USA,Franklin,WI,44.2127373,-91.123762
11/20/2016,USA,Pamplin,VA,37.2634817,-78.6825049
11/19/2016,USA,Apollo Beach,FL,27.7729445,-82.3981418
11/19/2016,USA,Salt Lake City,UT,40.7670126,-111.8904307
11/19/2016,USA,Myrtle Beach,SC,33.6956461,-78.8900408
11/19/2016,USA,Oregon City,OR,45.3573429,-122.6067582
11/19/2016,USA,San Marcos,CA,33.1433723,-117.1661448
11/19/2016,USA,Jefferson City,MO,38.577359,-92.1724264
11/19/2016,CANADA,Victoria,BC,48.4283327,-123.3649268
11/19/2016,USA,Boynton Beach,FL,26.5253491,-80.0664308
11/19/2016,USA,Brandon,FL,27.928464,-82.2880445
11/19/2016,USA,Zephyrhills,FL,28.2336196,-82.1811946
11/19/2016,USA,Bristol,CT,37.9317492,-122.0327847
11/19/2016,USA,Woodbridge,VA,38.658172,-77.2497049
11/19/2016,USA,Fishers,IN,39.9555928,-86.0138728
11/19/2016,USA,Louisville,KY,38.2542376,-85.7594069
11/19/2016,USA,Woodbridge,VA,38.658172,-77.2497049
11/19/2016,USA,Blaine,MN,45.1607987,-93.2349488
11/19/2016,USA,Ferrisburgh,VT,44.205835,-73.2465359
11/19/2016,USA,Springfield,MA,42.1014831,-72.5898109
11/19/2016,USA,Newnan,GA,33.3806716,-84.7996572
11/19/2016,USA,Largo,FL,27.9094665,-82.7873243
11/19/2016,USA,Cape Coral,FL,26.6058996,-81.9807339
11/19/2016,USA,Wichita,KS,37.6922361,-97.3375447
11/19/2016,USA,Smithton,PA,40.1539613,-79.7411534
11/19/2016,USA,Obernburg,NY,41.8448104,-75.0071096
11/18/2016,USA,Columbus,OH,39.9622601,-83.0007064
11/18/2016,USA,Sioux Falls,SD,43.5499749,-96.7003269
11/18/2016,USA,Fletcher,NC,35.4306712,-82.5012315
11/18/2016,USA,Billings,MT,45.7874957,-108.4960699
11/18/2016,USA,Billings,MT,45.7874957,-108.4960699
11/18/2016,USA,Stone Creek,OH,40.3972892,-81.5620642
11/18/2016,USA,Carrollton,OH,40.5728404,-81.0856531
11/18/2016,USA,Hampton,VA,37.0300969,-76.3452056
11/18/2016,USA,Nashville,TN,36.1622296,-86.774353
11/18/2016,USA,Kittery,ME,43.1033619,-70.7851622
11/18/2016,USA,McMurray,PA,40.2790921,-80.1017976
11/18/2016,USA,Bronx,NY,40.85703325,-73.83669606
11/18/2016,USA,New York City,NY,40.7305991,-73.9865811
11/18/2016,USA,Farmington,NH,43.39008,-71.0657499
11/17/2016,USA,Buena Park,CA,33.870413,-117.9962164
11/17/2016,USA,Athens,OH,39.3292396,-82.1012554
11/17/2016,USA,Methuen,MA,42.7262016,-71.1908923
11/17/2016,USA,Benton City,WA,46.2631897,-119.4878019
11/17/2016,USA,Stevens Point,WI,44.5229223,-89.5741109
11/17/2016,USA,High Point,NC,35.9556924,-80.0053175
11/17/2016,USA,Caldwell,ID,43.6678736,-116.6894155
11/17/2016,USA,Balko,OK,36.6600752,-100.679207
11/17/2016,USA,Jordan,MT,47.32121,-106.9104609
11/17/2016,USA,Elizabethton,TN,36.3487196,-82.2106875
11/17/2016,USA,Lower Burrell,PA,40.5882821,-79.7298186
11/17/2016,USA,Hemet,CA,33.778562,-117.0357665
11/17/2016,USA,Nampa,ID,43.5737361,-116.5596312
11/17/2016,USA,Oshkosh,WI,44.0206919,-88.5408573
11/17/2016,USA,Avon,CO,39.6329025,-106.4711837
11/17/2016,USA,Stonington,ME,44.156593,-68.6672969
11/16/2016,USA,Elk Grove,CA,38.4087993,-121.3716177
11/16/2016,USA,Benson,AZ,31.9678731,-110.2945759
11/16/2016,USA,Schenectady,NY,42.8095455,-74.0216719
11/16/2016,CANADA,London,ON,42.988576,-81.2466429
11/16/2016,USA,Middleton,ID,43.7068282,-116.6201356
11/16/2016,USA,Danville,KY,37.6456488,-84.7721822
11/16/2016,USA,Maple Grove,MN,45.0759797,-93.4561051
11/16/2016,USA,Lake Havasu City,AZ,34.4742786,-114.3440009
11/16/2016,USA,Maricopa,AZ,33.34883,-112.4912299
11/16/2016,USA,Carlton,OR,45.2942822,-123.1764948
11/16/2016,USA,Wood Village,OR,45.5372449,-122.4178386
11/16/2016,USA,Green Garden Township,IL,46.4385488,-87.2793086
11/16/2016,CANADA,Banff,AB,51.1777781,-115.5682503
11/16/2016,USA,Frostproof,FL,27.7458626,-81.5306312
11/16/2016,USA,Egg Harbor Township,NJ,39.3851791,-74.6756877
11/16/2016,USA,Shady Cove,OR,42.6109085,-122.8218511
11/16/2016,USA,Fremont,WI,44.2597027,-88.8648343
11/16/2016,USA,Mosinee,WI,44.7927298,-89.7035958
11/16/2016,USA,Clarksville,TN,36.5277607,-87.3588702
11/16/2016,USA,Richland,WA,46.2778406,-119.2769066
11/15/2016,USA,Bettendorf,IA,41.5255466,-90.5081477
11/15/2016,USA,Phoenix,AZ,33.4485866,-112.0773455
11/15/2016,USA,Portland,OR,45.5202471,-122.6741948
11/15/2016,USA,Stevens Point,WI,44.5229223,-89.5741109
11/15/2016,USA,Seattle,WA,47.6038321,-122.3300623
11/15/2016,CANADA,Prince Albert,SK,53.201097,-105.7489009
11/15/2016,USA,Stevens Point,WI,44.5229223,-89.5741109
11/15/2016,USA,Naperville,IL,41.7729107,-88.1478669
11/15/2016,USA,Berlin,WI,43.9680365,-88.9434476
11/15/2016,USA,Tahlequah,OK,35.91537,-94.9699559
11/15/2016,USA,Glendale,AZ,33.5389854,-112.1858156
11/15/2016,USA,Old Washington,OH,40.0386822,-81.444562
11/15/2016,USA,Saltillo,MS,34.3764923,-88.68172
11/15/2016,USA,Portland,OR,45.5202471,-122.6741948
11/14/2016,USA,Hillsboro,OR,45.5228939,-122.9898269
11/14/2016,USA,Gardena,CA,33.888658,-118.3076479
11/14/2016,USA,Longmont,CO,40.1672117,-105.1019286
11/14/2016,USA,Deltona,FL,28.9005446,-81.2636737
11/14/2016,USA,Central City,NE,41.1158475,-98.0017248
11/14/2016,USA,Irving,TX,32.8629195,-96.97917017
11/14/2016,USA,Jacksonville,FL,30.3321838,-81.6556509
11/14/2016,USA,Blanchardville,WI,42.81032,-89.8622148
11/14/2016,USA,Columbus,OH,39.9622601,-83.0007064
11/14/2016,USA,Summerville,SC,33.0206179,-80.1747536
11/14/2016,USA,Waupaca,WI,44.3735635,-89.03185979
11/14/2016,USA,Wilkesboro,NC,36.145965,-81.16064
11/14/2016,CANADA,Pickering,ON,43.8356637,-79.0905385
11/14/2016,USA,Fresno,CA,36.7295295,-119.7088612
11/14/2016,USA,Glendale,AZ,33.5389854,-112.1858156
11/13/2016,USA,Benson,VT,43.71558845,-73.30815198
11/13/2016,USA,Palmyra,PA,40.3089798,-76.5933012
11/13/2016,USA,North Chesterfield,VA,38.6560565,-90.5742028
11/13/2016,USA,Coconut Creek,FL,26.2714628,-80.18180782
11/13/2016,USA,Chesapeake Bay,MD,38.5167886,-76.3830045
11/13/2016,CANADA,Ottawa,ON,45.4210328,-75.6900218
11/13/2016,USA,Chester,SD,43.894974,-96.9264449
11/13/2016,USA,Centerville,OH,39.6283928,-84.1593817
11/13/2016,USA,Gila Bend,AZ,32.9478267,-112.7168238
11/13/2016,USA,Selma,IN,32.4078632,-87.0207472
11/13/2016,CANADA,Grande Prairie,AB,55.171025,-118.7951659
11/13/2016,USA,Benicia,CA,38.049365,-122.1585776
11/13/2016,USA,Monroeville,PA,40.4211798,-79.7881024
11/13/2016,USA,Wheaton,MD,39.0398314,-77.0552554
11/13/2016,USA,Ottawa,IL,41.3516628,-88.8454359
11/13/2016,USA,Elwood,IL,41.4039201,-88.1117241
11/13/2016,USA,Bagley,IA,41.8460964,-94.4299693
11/13/2016,USA,Grand Rapids,MI,42.9632405,-85.6678638
11/13/2016,USA,Stockton,CA,37.9577016,-121.2907795
12/11/2016,USA,Maryville,TN,35.7564719,-83.9704592
12/11/2016,USA,Andersonville,TN,36.1986898,-84.0371391
12/11/2016,USA,Auburn,WA,47.3075369,-122.2301807
12/11/2016,USA,Baltimore,MD,39.2908816,-76.6107589
12/11/2016,USA,New Market,MD,39.3826031,-77.2694277
12/11/2016,USA,Chesterfield,MI,38.6560565,-90.5742028
12/11/2016,USA,Highland Park,IL,42.1816919,-87.8003437
12/11/2016,USA,Melbourne,FL,28.0836269,-80.6081088
12/11/2016,USA,Glendale,AZ,33.5389854,-112.1858156
12/11/2016,USA,Durham,NC,35.9940329,-78.8986189
12/11/2016,USA,Fountain Hill,AR,33.3578937,-91.8504083
12/11/2016,USA,Bethesda,MD,38.9848265,-77.0946458
12/11/2016,USA,Bristol,VA,36.5959685,-82.1885008
12/11/2016,USA,Twin Falls,ID,42.5704219,-114.460317
12/11/2016,USA,Bloomfield Hills,MI,42.583645,-83.2454882
12/11/2016,USA,Louisville,KY,38.2542376,-85.7594069
12/11/2016,USA,Freeport,NY,40.6576022,-73.5831834
11/11/2016,USA,Middletown,DE,39.449556,-75.7163206
11/11/2016,USA,Alabaster,AL,33.2442813,-86.8163772
11/11/2016,USA,Owatonna,MN,44.0839937,-93.2261075
11/11/2016,USA,Jasper County,IA,41.6791308,-93.0647785
11/11/2016,USA,Anchorage,AK,61.2163129,-149.8948522
11/11/2016,USA,Terra Linda,CA,38.0040893,-122.5496999
11/11/2016,USA,Terra Linda,CA,38.0040893,-122.5496999
11/11/2016,USA,Raleigh,NC,35.7803977,-78.6390988
11/11/2016,USA,Phoenix,AZ,33.4485866,-112.0773455
11/11/2016,USA,Boca Raton,FL,26.3586885,-80.0830983
11/11/2016,USA,Salt Lake City,UT,40.7670126,-111.8904307
11/11/2016,USA,West Palm Beach,FL,26.7153425,-80.0533745
11/11/2016,USA,Nashua,NH,42.7653662,-71.4675659
11/11/2016,USA,Moss Point,MS,30.4115881,-88.53446
11/11/2016,USA,Greeley,CO,38.4570355,-101.8185006
11/11/2016,USA,West Salem,OR,44.9482087,-123.0629462
11/11/2016,USA,Keizer,OR,44.9958075,-123.0197172
11/11/2016,USA,Herod,IL,37.5803268,-88.4361546
11/11/2016,USA,Leominster,MA,42.5250906,-71.7597939
The whole thing is too big to post but this should get us started.
I fix up the dates and filter the data for a country and state
ufodata <-read.csv("UFO.csv", header=TRUE)
new.date<- strptime(ufodata$Date, format="%m/%d/%Y")
UFO<-cbind(ufodata, new.date)
stateselect <- UFO %>% filter(State=="VA",Country=="USA")
statesorted<-stateselect[order(stateselect$new.date),]
So I now have a dataframe called stateselect that has just the sighting for Virginia. R Studio shows it as 108 observations of 7 variables...that jives with my 6 original columns plus the new date.
But if I run
summary(stateselect)
Date Country City State lat lng new.date
11/3/2016 : 4 CANADA: 0 Virginia Beach:11 VA :108 Min. :33.72 Min. :-116.27 Min. :2016-01-06 00:00:00
2/12/2016 : 3 USA :108 Fredericksburg: 5 AB : 0 1st Qu.:36.89 1st Qu.: -78.74 1st Qu.:2016-03-17 18:00:00
1/30/2016 : 2 Stafford : 4 AK : 0 Median :37.64 Median : -77.46 Median :2016-07-10 00:00:00
10/11/2016: 2 Woodbridge : 4 AL : 0 Mean :37.75 Mean : -78.79 Mean :2016-06-26 20:48:20
10/12/2016: 2 Arlington : 3 AR : 0 3rd Qu.:38.66 3rd Qu.: -77.08 3rd Qu.:2016-10-04 12:00:00
11/19/2016: 2 Portsmouth : 3 AZ : 0 Max. :39.61 Max. : -75.38 Max. :2016-12-21 00:00:00
(Other) :93 (Other) :78 (Other): 0
So why does Canada still show up under Country and all the other states show up under State? What I'd like to do next is get the names of the cities in Virginia. But if I run
unique(stateselect$City)
[1] Waynesboro North Chesterfield Virginia Beach Arlington Fredericksburg Raphine
[7] Chester Ashland Tazewell Alexandria Pearisburg Pamplin
[13] Woodbridge Hampton Bristol Ashburn Charlottesville Colonial Beach
[19] Reston Springfield Petersburg Prince William False Cape State Park Spotsylvania
[25] Manassas Falls Church Gainesville Newport News Williamsburg Comer's Rock
[31] Fairfax Big Stone Gap Roanoke Chincoteague Hiltons Midlothian
[37] Farmville Marion Hurt Salem Madison Heights Aldie
[43] Portsmouth Front Royal Occoquan Stanley Covington Richmond
[49] Lynchburg Chesapeake Vinton Buckingham Stafford Winchester
[55] Burke Centreville Martinsville Radford Culpeper Hillsville
[61] Route 66 West Manassas Park Ivor Danville Rockville Suffolk
[67] Stanardsville
2626 Levels: 495 Maryland Hwy Aberdeen Aberdeen Gardens Abilene Abiquiu Absecon Accord Acworth Adairsville Adrian Agoura Hills Aiken ... Zion
You can see the 67 city names from Virginia, but there's also the "2626 Levels" stuff. So if I try to store the output
names <- unique(stateselect$City)
names is now a factor with 2626 levels. I'm thoroughly confused....
Try:
ufodata <- read.csv("UFO.csv", header=TRUE, stringsAsFactors = FALSE)
You are seeing variables with zero values and levels because the states and countries were converted to factors during import. You probably want them to stay as strings (characters).

Plotting Conditionally Summed Data (base R or ggplot)

I started with a dataframe containing info on West Nile cases in Canada from 2012-2015. 600 observations of 10 variables in total.
> head(mosquitoes)
Years Weeks Province Avg.Temp Avg..Precepitation Wind Number.of.cases Number.of.Dead.Birds Mosquito.Pools.Tested Google.Trend.Searches
1 2015 17 Alberta 48 0.01 8 0 0 0 1
2 2015 18 Alberta 46 0.03 10 0 0 0 2
3 2015 19 Alberta 44 0.07 8 0 0 0 2
4 2015 20 Alberta 51 0.00 9 0 0 0 2
5 2015 21 Alberta 56 0.01 9 0 0 0 4
6 2015 22 Alberta 58 0.10 7 0 0 0 1
Here is the entire data set....sorry it's large.
Years,Weeks,Province,Avg Temp ,Avg. Precepitation,Wind,Number of cases,Number of Dead Birds,Mosquito Pools Tested,Google Trend Searches
2015,17,Alberta,48,0.01,8,0,0,0,1
2015,18,Alberta,46,0.03,10,0,0,0,2
2015,19,Alberta,44,0.07,8,0,0,0,2
2015,20,Alberta,51,0,9,0,0,0,2
2015,21,Alberta,56,0.01,9,0,0,0,4
2015,22,Alberta,58,0.1,7,0,0,0,1
2015,23,Alberta,61,0.05,8,0,0,0,1
2015,24,Alberta,55,0.08,9,0,0,0,1
2015,25,Alberta,63,0.02,6,0,0,0,4
2015,26,Alberta,67,0.16,8,0,0,0,5
2015,27,Alberta,65,0.02,8,0,0,0,3
2015,28,Alberta,62,0.09,10,0,0,0,7
2015,29,Alberta,66,0.01,8,0,0,0,2
2015,30,Alberta,62,0.02,7,0,0,0,3
2015,31,Alberta,64,0.21,7,0,0,0,6
2015,32,Alberta,66,0.07,7,0,0,0,4
2015,33,Alberta,55,0.13,8,0,0,0,4
2015,34,Alberta,63,0,6,0,0,0,1
2015,35,Alberta,52,0.11,9,0,0,0,4
2015,36,Alberta,54,0.02,7,0,0,0,2
2015,37,Alberta,48,0.06,8,0,0,0,2
2015,38,Alberta,52,0.03,9,0,0,0,3
2015,39,Alberta,49,0.03,9,0,0,0,3
2015,40,Alberta,51,0,8,0,0,0,2
2015,41,Alberta,48,0,8,0,0,0,2
2014,17,Alberta,43,0.05,8,0,0,0,1
2014,18,Alberta,44,0.06,9,0,0,0,3
2014,19,Alberta,37,0.03,9,0,0,0,3
2014,20,Alberta,48,0.01,8,0,0,0,1
2014,21,Alberta,57,0.01,10,0,0,0,2
2014,22,Alberta,53,0.06,8,0,0,0,4
2014,23,Alberta,53,0.04,10,0,0,0,6
2014,24,Alberta,53,0.04,10,0,0,0,6
2014,25,Alberta,54,0.24,9,0,0,0,4
2014,26,Alberta,59,0.03,9,0,0,0,7
2014,27,Alberta,64,0.02,11,0,0,0,19
2014,28,Alberta,65,0.03,10,0,0,0,33
2014,29,Alberta,67,0.01,9,0,0,0,18
2014,30,Alberta,62,0.08,10,0,0,0,14
2014,31,Alberta,68,0,10,0,0,0,10
2014,32,Alberta,63,0.16,8,0,0,0,11
2014,33,Alberta,66,0.01,7,0,0,0,19
2014,34,Alberta,58,0.05,8,0,0,0,17
2014,35,Alberta,58,0.04,7,0,0,0,8
2014,36,Alberta,54,0.01,7,0,0,0,12
2014,37,Alberta,41,0.15,8,0,0,0,3
2014,38,Alberta,58,0,5,0,0,0,3
2014,39,Alberta,60,0.02,6,0,0,0,4
2014,40,Alberta,48,0.03,11,0,0,0,5
2014,41,Alberta,51,0,6,0,0,0,3
2013,17,Alberta,42,0,12,0,0,0,3
2013,18,Alberta,42,0.01,11,0,0,0,2
2013,19,Alberta,57,0,11,0,0,0,2
2013,20,Alberta,55,0.01,10,0,0,0,9
2013,21,Alberta,50,0.23,11,0,0,0,7
2013,22,Alberta,52,0.08,6,0,0,0,8
2013,23,Alberta,55,0.15,10,0,0,0,10
2013,24,Alberta,53,0.08,10,0,0,0,4
2013,25,Alberta,57,0.3,11,0,0,0,9
2013,26,Alberta,61,0.01,9,0,0,0,17
2013,27,Alberta,65,0.08,10,0,0,0,27
2013,28,Alberta,59,0.07,8,0,0,0,19
2013,29,Alberta,62,0.01,10,0,0,0,21
2013,30,Alberta,62,0.06,10,0,0,0,18
2013,31,Alberta,57,0.03,7,0,0,0,13
2013,32,Alberta,60,0.07,8,0,0,0,10
2013,33,Alberta,67,0,8,3,0,0,2
2013,34,Alberta,63,0,8,5,0,0,12
2013,35,Alberta,64,0.03,10,4,0,0,20
2013,36,Alberta,64,0.13,8,2,1,0,15
2013,37,Alberta,63,0,9,5,0,0,9
2013,38,Alberta,57,0.06,11,2,0,0,11
2013,39,Alberta,47,0,10,0,0,0,4
2013,40,Alberta,44,0,11,0,0,0,5
2013,41,Alberta,45,0.06,8,0,0,0,5
2012,17,Alberta,49,0.06,7,0,0,0,2
2012,18,Alberta,42,0.13,9,0,0,0,2
2012,19,Alberta,48,0,9,0,0,0,6
2012,20,Alberta,53,0.01,10,0,0,0,2
2012,21,Alberta,49,0.08,8,0,0,0,2
2012,22,Alberta,52,0,9,0,0,0,2
2012,23,Alberta,54,0.28,9,0,0,0,4
2012,24,Alberta,56,0.21,12,0,0,0,7
2012,25,Alberta,56,0.05,8,0,0,0,5
2012,26,Alberta,59,0.14,8,0,0,0,3
2012,27,Alberta,61,0.21,9,0,0,0,22
2012,28,Alberta,69,0,8,0,0,0,32
2012,29,Alberta,65,0.09,10,0,0,0,16
2012,30,Alberta,64,0.02,10,0,0,0,15
2012,31,Alberta,63,0.03,10,0,0,0,20
2012,32,Alberta,68,0,10,0,0,0,25
2012,33,Alberta,62,0.07,10,4,0,0,36
2012,34,Alberta,62,0.05,10,2,0,0,100
2012,35,Alberta,61,0.01,10,0,0,0,76
2012,36,Alberta,57,0,12,1,0,0,29
2012,37,Alberta,57,0,12,2,0,0,30
2012,38,Alberta,59,0,9,0,0,0,14
2012,39,Alberta,58,0.01,9,0,0,0,11
2012,40,Alberta,43,0.07,12,0,0,0,10
2012,41,Alberta,43,0.02,13,0,0,0,7
2015,17,British Columbia,53,0.03,10,0,0,0,5
2015,18,British Columbia,53,0.01,6,0,0,0,5
2015,19,British Columbia,58,0.01,7,0,0,0,5
2015,20,British Columbia,60,0,7,0,0,0,4
2015,21,British Columbia,62,0,7,0,0,0,6
2015,22,British Columbia,60,0.03,7,0,0,0,9
2015,23,British Columbia,62,0,13,0,0,0,9
2015,24,British Columbia,62,0.02,8,0,0,0,10
2015,25,British Columbia,66,0,9,0,0,0,7
2015,26,British Columbia,70,0,12,0,0,0,5
2015,27,British Columbia,67,0.01,9,0,0,0,11
2015,28,British Columbia,66,0,10,0,0,0,9
2015,29,British Columbia,65,0.04,9,0,0,0,14
2015,30,British Columbia,65,0.04,6,0,0,0,7
2015,31,British Columbia,65,0.02,9,0,0,0,7
2015,32,British Columbia,66,0.04,9,0,0,0,9
2015,33,British Columbia,65,0,9,0,0,0,11
2015,34,British Columbia,64,0.1,7,0,0,0,6
2015,35,British Columbia,57,0.12,10,0,0,0,4
2015,36,British Columbia,61,0.02,9,0,0,0,9
2015,37,British Columbia,58,0.09,9,0,0,0,9
2015,38,British Columbia,55,0.04,9,0,0,0,3
2015,39,British Columbia,52,0,6,0,0,0,3
2015,40,British Columbia,56,0.08,6,0,0,0,3
2015,41,British Columbia,51,0.04,7,0,0,0,7
2014,17,British Columbia,49,0.07,10,0,0,0,3
2014,18,British Columbia,54,0.03,8,0,0,0,4
2014,19,British Columbia,53,0.18,9,0,0,0,4
2014,20,British Columbia,60,0,8,0,0,0,6
2014,21,British Columbia,59,0.06,7,0,0,0,6
2014,22,British Columbia,56,0.09,7,0,0,0,6
2014,23,British Columbia,59,0,8,0,0,0,8
2014,24,British Columbia,60,0.03,10,0,0,0,7
2014,25,British Columbia,58,0.09,9,0,0,0,8
2014,26,British Columbia,62,0.05,7,0,0,0,10
2014,27,British Columbia,64,0.01,8,0,0,0,7
2014,28,British Columbia,66,0.01,8,0,0,0,19
2014,29,British Columbia,68,0,9,0,0,0,13
2014,30,British Columbia,63,0.06,8,0,0,0,12
2014,31,British Columbia,67,0,6,0,0,0,16
2014,32,British Columbia,66,0,7,0,0,0,25
2014,33,British Columbia,67,0.08,7,0,0,0,17
2014,34,British Columbia,65,0,6,0,0,0,13
2014,35,British Columbia,66,0,7,0,0,0,30
2014,36,British Columbia,61,0.05,7,0,0,0,9
2014,37,British Columbia,60,0,6,0,0,0,11
2014,38,British Columbia,61,0.02,6,0,0,0,3
2014,39,British Columbia,62,0.12,9,0,0,0,8
2014,40,British Columbia,56,0.04,6,0,0,0,9
2014,41,British Columbia,58,0.03,5,0,0,0,7
2013,17,British Columbia,50,0.03,7,0,0,0,14
2013,18,British Columbia,50,0,12,0,0,0,8
2013,19,British Columbia,59,0.03,6,0,0,0,5
2013,20,British Columbia,56,0.07,8,0,0,0,7
2013,21,British Columbia,54,0.04,8,0,0,0,4
2013,22,British Columbia,55,0.09,7,0,0,0,8
2013,23,British Columbia,60,0.01,9,0,0,0,14
2013,24,British Columbia,58,0.01,7,0,0,0,16
2013,25,British Columbia,62,0.04,8,0,0,0,10
2013,26,British Columbia,63,0.1,7,0,0,0,17
2013,27,British Columbia,67,0,8,0,0,0,29
2013,28,British Columbia,63,0,8,0,0,0,30
2013,29,British Columbia,66,0,9,0,0,0,20
2013,30,British Columbia,64,0,8,0,0,0,34
2013,31,British Columbia,64,0.02,8,0,0,0,11
2013,32,British Columbia,66,0,6,0,0,1,13
2013,33,British Columbia,66,0.02,8,0,0,1,16
2013,34,British Columbia,63,0.01,8,0,0,1,16
2013,35,British Columbia,65,0.17,7,0,1,1,12
2013,36,British Columbia,64,0.06,6,0,0,1,8
2013,37,British Columbia,63,0,6,0,0,1,14
2013,38,British Columbia,60,0.19,6,0,0,1,6
2013,39,British Columbia,54,0.23,10,0,0,1,6
2013,40,British Columbia,51,0.15,9,0,0,1,6
2013,41,British Columbia,51,0.01,8,0,0,1,8
2012,17,British Columbia,53,0.05,8,0,0,0,5
2012,18,British Columbia,50,0.11,7,0,0,0,6
2012,19,British Columbia,52,0,9,0,0,0,7
2012,20,British Columbia,54,0,10,0,0,0,8
2012,21,British Columbia,55,0.06,8,0,0,0,9
2012,22,British Columbia,57,0.07,7,0,0,0,8
2012,23,British Columbia,53,0.07,8,0,0,0,4
2012,24,British Columbia,57,0.04,8,0,0,0,4
2012,25,British Columbia,58,0.13,8,0,0,0,7
2012,26,British Columbia,60,0.04,8,0,0,0,8
2012,27,British Columbia,59,0.03,7,0,0,0,22
2012,28,British Columbia,66,0,6,0,0,0,30
2012,29,British Columbia,66,0.05,8,0,0,0,30
2012,30,British Columbia,63,0.03,8,0,0,0,38
2012,31,British Columbia,65,0,8,0,0,0,60
2012,32,British Columbia,67,0.01,8,0,0,0,34
2012,33,British Columbia,69,0,7,0,0,0,63
2012,34,British Columbia,63,0,8,0,0,0,100
2012,35,British Columbia,62,0,7,0,0,0,51
2012,36,British Columbia,62,0,7,0,0,0,32
2012,37,British Columbia,58,0.01,8,0,0,0,24
2012,38,British Columbia,60,0,6,0,0,0,13
2012,39,British Columbia,57,0,6,0,0,0,13
2012,40,British Columbia,53,0,8,0,0,0,6
2012,41,British Columbia,52,0.09,5,0,0,0,8
2015,17,Manitoba,56,0,10,0,0,0,4
2015,18,Manitoba,48,0,13,0,0,0,4
2015,19,Manitoba,46,0,10,0,0,0,4
2015,20,Manitoba,52,0,14,0,0,0,4
2015,21,Manitoba,57,0,10,0,0,12,4
2015,22,Manitoba,60,0,12,0,0,4,8
2015,23,Manitoba,67,0,9,0,0,87,8
2015,24,Manitoba,59,0,9,0,0,82,8
2015,25,Manitoba,66,0,7,0,0,44,8
2015,26,Manitoba,68,0,7,0,0,75,11
2015,27,Manitoba,66,0,10,0,0,73,17
2015,28,Manitoba,70,0,7,0,0,132,8
2015,29,Manitoba,69,0,9,0,0,139,17
2015,30,Manitoba,70,0,11,0,0,204,4
2015,31,Manitoba,63,0,9,0,0,275,13
2015,32,Manitoba,73,0,9,0,0,195,23
2015,33,Manitoba,62,0,10,0,0,228,13
2015,34,Manitoba,62,0,11,0,0,69,12
2015,35,Manitoba,73,0,11,1,0,92,10
2015,36,Manitoba,57,0,10,1,0,113,8
2015,37,Manitoba,60,0,11,2,0,34,4
2015,38,Manitoba,61,0,13,1,0,0,4
2015,39,Manitoba,53,0,13,0,0,0,6
2015,40,Manitoba,48,0,11,0,0,0,6
2015,41,Manitoba,44,0,11,0,0,0,6
2014,17,Manitoba,42,0,11,0,0,0,4
2014,18,Manitoba,42,0,14,0,0,0,0
2014,19,Manitoba,46,0,9,0,0,0,0
2014,20,Manitoba,45,0,10,0,0,0,0
2014,21,Manitoba,57,0,12,0,0,0,0
2014,22,Manitoba,66,0,8,0,0,0,0
2014,23,Manitoba,62,0,10,0,0,0,5
2014,24,Manitoba,60,0,11,0,0,0,13
2014,25,Manitoba,62,0,12,0,0,0,9
2014,26,Manitoba,66,0,10,0,0,0,7
2014,27,Manitoba,65,0,15,0,0,0,9
2014,28,Manitoba,67,0,11,0,0,0,36
2014,29,Manitoba,63,0,11,0,0,0,24
2014,30,Manitoba,68,0,9,0,0,0,53
2014,31,Manitoba,65,0,8,0,0,7,41
2014,32,Manitoba,71,0,8,0,0,7,48
2014,33,Manitoba,68,0,8,1,0,14,14
2014,34,Manitoba,67,0,8,2,0,19,18
2014,35,Manitoba,61,0,11,2,0,22,9
2014,36,Manitoba,60,0,8,0,0,24,4
2014,37,Manitoba,50,0,11,0,0,24,11
2014,38,Manitoba,52,0,10,0,0,24,4
2014,39,Manitoba,65,0,13,0,0,24,15
2014,40,Manitoba,47,0,16,0,0,24,4
2014,41,Manitoba,39,0,13,0,0,24,4
2013,17,Manitoba,36,0.01,12,0,0,0,4
2013,18,Manitoba,38,0.11,9,0,0,0,4
2013,19,Manitoba,49,0.02,12,0,0,0,4
2013,20,Manitoba,56,0.02,10,0,0,0,5
2013,21,Manitoba,55,0.05,14,0,0,0,4
2013,22,Manitoba,58,0.16,15,0,0,0,4
2013,23,Manitoba,57,0.01,9,0,0,0,9
2013,24,Manitoba,63,0.03,10,0,0,0,16
2013,25,Manitoba,66,0.1,9,0,0,0,23
2013,26,Manitoba,69,0.24,10,0,0,0,14
2013,27,Manitoba,72,0,6,0,0,0,23
2013,28,Manitoba,70,0.06,10,0,0,1,19
2013,29,Manitoba,66,0.1,9,0,0,1,45
2013,30,Manitoba,60,0.19,8,0,1,7,35
2013,31,Manitoba,61,0.03,7,0,0,10,31
2013,32,Manitoba,59,0.04,7,0,0,16,22
2013,33,Manitoba,64,0.02,8,1,0,16,24
2013,34,Manitoba,71,0.17,10,0,0,16,49
2013,35,Manitoba,76,0.01,7,0,0,17,14
2013,36,Manitoba,64,0,10,1,0,17,11
2013,37,Manitoba,63,0.01,8,0,0,19,9
2013,38,Manitoba,54,0,11,0,0,19,6
2013,39,Manitoba,60,0.1,12,0,0,19,13
2013,40,Manitoba,50,0.03,11,0,0,19,8
2013,41,Manitoba,52,0,10,0,1,19,4
2012,17,Manitoba,46,0.01,12,0,0,0,0
2012,18,Manitoba,51,0.05,11,0,0,0,0
2012,19,Manitoba,56,0.06,13,0,0,0,5
2012,20,Manitoba,58,0.16,12,0,0,0,6
2012,21,Manitoba,53,0.02,11,0,0,0,5
2012,22,Manitoba,53,0.13,9,0,0,0,5
2012,23,Manitoba,67,0.08,8,0,0,0,8
2012,24,Manitoba,62,0.17,11,0,0,0,10
2012,25,Manitoba,60,0.04,8,0,0,0,11
2012,26,Manitoba,68,0,10,0,0,0,11
2012,27,Manitoba,73,0.03,7,0,0,0,15
2012,28,Manitoba,73,0,7,0,0,0,17
2012,29,Manitoba,69,0.05,8,1,0,2,21
2012,30,Manitoba,71,0,8,1,0,20,36
2012,31,Manitoba,71,0.2,9,4,0,48,100
2012,32,Manitoba,67,0,9,7,0,62,47
2012,33,Manitoba,62,0.04,8,7,0,98,31
2012,34,Manitoba,69,0.01,7,6,0,108,84
2012,35,Manitoba,70,0.01,11,7,0,111,75
2012,36,Manitoba,63,0.01,11,1,0,116,22
2012,37,Manitoba,59,0.01,11,3,0,116,23
2012,38,Manitoba,47,0.01,12,2,0,116,13
2012,39,Manitoba,50,0,8,0,0,116,5
2012,40,Manitoba,46,0.02,15,0,0,116,7
2012,41,Manitoba,37,0.02,10,0,0,116,5
2015,17,Quebec,53,0,8,0,0,0,8
2015,18,Quebec,65,0.06,8,0,0,0,8
2015,19,Quebec,58,0.09,10,0,0,0,8
2015,20,Quebec,59,0.05,11,0,0,0,8
2015,21,Quebec,69,0.11,11,0,0,0,8
2015,22,Quebec,56,0.07,9,0,0,0,8
2015,23,Quebec,65,0.16,9,0,0,0,8
2015,24,Quebec,64,0.16,7,0,0,0,16
2015,25,Quebec,67,0.18,8,0,0,0,8
2015,26,Quebec,64,0.07,9,0,0,120,19
2015,27,Quebec,71,0.01,8,0,0,127,24
2015,28,Quebec,70,0.05,9,0,1,132,24
2015,29,Quebec,70,0.3,8,0,1,131,16
2015,30,Quebec,75,0.07,9,1,2,129,16
2015,31,Quebec,67,0.02,9,1,3,126,8
2015,32,Quebec,69,0.31,7,0,0,133,8
2015,33,Quebec,76,0.11,9,1,1,125,16
2015,34,Quebec,68,0.01,8,2,1,123,11
2015,35,Quebec,70,0,8,1,3,131,31
2015,36,Quebec,72,0.15,8,2,4,128,15
2015,37,Quebec,69,0.21,9,6,0,123,7
2015,38,Quebec,58,0,7,5,0,108,7
2015,39,Quebec,55,0.17,11,2,2,107,11
2015,40,Quebec,49,0.03,7,5,0,0,7
2015,41,Quebec,51,0.11,11,8,0,0,15
2014,17,Quebec,46,0.05,9,0,0,0,0
2014,18,Quebec,49,0.18,12,0,0,0,0
2014,19,Quebec,53,0.09,10,0,0,0,0
2014,20,Quebec,62,0.17,13,0,0,0,0
2014,21,Quebec,59,0.01,9,0,0,0,13
2014,22,Quebec,59,0.08,9,0,0,0,13
2014,23,Quebec,66,0.13,8,0,0,0,40
2014,24,Quebec,66,0.28,11,0,0,0,18
2014,25,Quebec,65,0.14,8,0,0,0,27
2014,26,Quebec,69,0.14,6,0,0,0,33
2014,27,Quebec,75,0.02,9,0,0,0,23
2014,28,Quebec,70,0.08,12,0,0,0,40
2014,29,Quebec,69,0.05,9,0,0,1,27
2014,30,Quebec,72,0.06,10,0,0,4,28
2014,31,Quebec,66,0.18,8,0,0,9,54
2014,32,Quebec,70,0.04,6,0,0,10,24
2014,33,Quebec,67,0.2,10,1,2,19,34
2014,34,Quebec,66,0,7,1,0,19,9
2014,35,Quebec,70,0,8,1,1,39,17
2014,36,Quebec,72,0.11,10,1,0,70,8
2014,37,Quebec,60,0.12,9,0,3,99,12
2014,38,Quebec,52,0.02,9,1,2,112,13
2014,39,Quebec,61,0.02,9,0,0,119,15
2014,40,Quebec,58,0.06,11,0,1,119,16
2014,41,Quebec,51,0.1,13,1,0,119,16
2013,17,Quebec,46,0.03,11,1,0,0,9
2013,18,Quebec,60,0.01,7,0,0,0,9
2013,19,Quebec,65,0.08,8,0,0,0,9
2013,20,Quebec,51,0.01,11,0,0,0,18
2013,21,Quebec,64,0.19,10,0,0,0,17
2013,22,Quebec,64,0.18,9,0,0,0,9
2013,23,Quebec,59,0.11,10,0,0,0,21
2013,24,Quebec,64,0.11,9,0,0,0,18
2013,25,Quebec,62,0.09,8,0,0,0,9
2013,26,Quebec,69,0.14,9,0,0,0,37
2013,27,Quebec,72,0.02,9,0,0,0,9
2013,28,Quebec,73,0.06,8,0,0,0,45
2013,29,Quebec,79,0.28,9,0,0,2,49
2013,30,Quebec,66,0.06,7,0,0,3,73
2013,31,Quebec,70,0.12,9,1,3,5,40
2013,32,Quebec,68,0.04,9,3,2,11,74
2013,33,Quebec,66,0.08,9,8,4,23,56
2013,34,Quebec,69,0.02,10,3,5,36,64
2013,35,Quebec,70,0.06,7,4,9,36,29
2013,36,Quebec,63,0.06,10,2,6,40,32
2013,37,Quebec,62,0.18,8,3,4,47,20
2013,38,Quebec,58,0.12,9,1,2,59,8
2013,39,Quebec,54,0.03,6,1,0,60,16
2013,40,Quebec,61,0,6,1,0,60,24
2013,41,Quebec,55,0.11,10,0,0,60,20
2012,17,Quebec,40,0.17,13,0,0,0,0
2012,18,Quebec,50,0.03,7,0,0,0,10
2012,19,Quebec,55,0.07,8,0,0,0,10
2012,20,Quebec,61,0.02,7,0,0,0,10
2012,21,Quebec,69,0.1,7,0,0,0,11
2012,22,Quebec,62,0.16,8,0,0,0,10
2012,23,Quebec,61,0.02,8,0,0,0,10
2012,24,Quebec,68,0.08,7,0,0,0,11
2012,25,Quebec,76,0.01,9,0,0,0,11
2012,26,Quebec,69,0.13,9,0,0,0,26
2012,27,Quebec,73,0.12,6,0,0,0,40
2012,28,Quebec,72,0,8,0,2,0,24
2012,29,Quebec,71,0.21,6,1,0,0,11
2012,30,Quebec,71,0.1,7,1,0,0,11
2012,31,Quebec,76,0.01,7,0,1,5,78
2012,32,Quebec,72,0.17,10,2,5,8,31
2012,33,Quebec,70,0.02,7,6,2,19,94
2012,34,Quebec,70,0,6,10,5,19,100
2012,35,Quebec,71,0.01,11,9,8,19,76
2012,36,Quebec,71,0.11,6,14,1,19,70
2012,37,Quebec,63,0.07,8,23,6,19,43
2012,38,Quebec,58,0.12,10,16,0,19,34
2012,39,Quebec,54,0.01,9,27,0,19,38
2012,40,Quebec,57,0.16,8,11,0,19,14
2012,41,Quebec,45,0.06,10,8,0,19,19
2015,17,Ontario,53,0,9,0,0,0,2
2015,18,Ontario,61,0.04,5,0,0,0,2
2015,19,Ontario,58,0.07,7,0,0,0,4
2015,20,Ontario,58,0,8,0,0,0,5
2015,21,Ontario,70,0.11,8,0,0,0,8
2015,22,Ontario,57,0.14,7,0,0,180,8
2015,23,Ontario,65,0.18,6,0,0,356,5
2015,24,Ontario,65,0.08,5,0,1,852,5
2015,25,Ontario,67,0.33,7,0,0,886,13
2015,26,Ontario,63,0.02,7,0,0,954,15
2015,27,Ontario,68,0.04,5,0,0,1152,13
2015,28,Ontario,67,0.03,6,1,0,1216,21
2015,29,Ontario,72,0.01,7,1,4,1219,16
2015,30,Ontario,76,0.03,6,1,1,1222,22
2015,31,Ontario,68,0.06,6,0,8,1176,24
2015,32,Ontario,69,0.21,6,0,0,1168,15
2015,33,Ontario,73,0.09,5,1,0,1168,24
2015,34,Ontario,64,0.01,5,5,1,987,12
2015,35,Ontario,75,0,5,2,1,881,18
2015,36,Ontario,70,0.11,5,5,0,802,9
2015,37,Ontario,65,0.07,6,1,2,712,6
2015,38,Ontario,60,0,5,5,4,526,4
2015,39,Ontario,55,0.04,9,2,2,396,6
2015,40,Ontario,53,0.14,6,3,0,65,5
2015,41,Ontario,52,0.04,8,3,4,0,2
2014,17,Ontario,46,0.05,8,0,0,0,3
2014,18,Ontario,47,0.14,9,0,0,0,2
2014,19,Ontario,53,0,9,0,0,0,2
2014,20,Ontario,56,0.13,6,0,0,0,3
2014,21,Ontario,57,0.09,5,0,0,0,4
2014,22,Ontario,65,0.02,6,0,0,0,7
2014,23,Ontario,63,0.04,6,0,0,0,10
2014,24,Ontario,65,0.19,6,0,0,0,16
2014,25,Ontario,66,0.16,5,0,0,0,13
2014,26,Ontario,69,0.06,4,0,0,0,7
2014,27,Ontario,72,0.09,7,0,0,0,20
2014,28,Ontario,68,0.12,6,0,0,0,17
2014,29,Ontario,66,0.21,5,1,0,0,13
2014,30,Ontario,68,0.03,5,0,0,2,14
2014,31,Ontario,67,0.35,5,0,0,5,35
2014,32,Ontario,68,0.21,4,0,0,9,22
2014,33,Ontario,65,0.12,7,2,0,11,30
2014,34,Ontario,67,0.02,4,0,2,13,11
2014,35,Ontario,67,0,6,2,3,30,18
2014,36,Ontario,71,0.39,5,5,0,43,13
2014,37,Ontario,60,0.15,6,1,0,52,10
2014,38,Ontario,53,0.02,4,0,1,56,7
2014,39,Ontario,60,0.08,4,0,0,56,3
2014,40,Ontario,61,0.06,4,0,0,56,6
2014,41,Ontario,50,0.06,6,0,0,56,4
2013,17,Ontario,43,0.05,6,0,0,0,2
2013,18,Ontario,57,0.05,6,0,0,0,3
2013,19,Ontario,59,0.04,5,0,0,0,4
2013,20,Ontario,51,0.02,8,0,0,0,3
2013,21,Ontario,60,0.17,8,0,0,0,7
2013,22,Ontario,64,0.16,6,1,0,0,9
2013,23,Ontario,58,0.05,7,1,0,0,9
2013,24,Ontario,64,0.29,6,0,0,0,12
2013,25,Ontario,64,0.11,5,0,0,0,12
2013,26,Ontario,73,0.06,4,0,1,2,12
2013,27,Ontario,71,0.05,5,1,0,2,20
2013,28,Ontario,72,0.13,6,2,0,4,15
2013,29,Ontario,80,0.05,5,1,2,12,20
2013,30,Ontario,65,0.12,6,5,0,22,56
2013,31,Ontario,66,0.26,5,4,8,41,43
2013,32,Ontario,67,0.04,6,5,6,65,32
2013,33,Ontario,63,0,5,5,2,89,24
2013,34,Ontario,70,0,5,2,0,131,30
2013,35,Ontario,72,0.2,3,2,8,155,22
2013,36,Ontario,63,0.12,6,7,2,179,12
2013,37,Ontario,64,0.04,6,3,2,190,15
2013,38,Ontario,57,0.17,4,5,2,194,9
2013,39,Ontario,55,0,4,0,1,196,5
2013,40,Ontario,61,0.04,4,5,0,198,9
2013,41,Ontario,56,0.04,4,1,0,198,4
2012,17,Ontario,40,0.06,11,0,0,0,4
2012,18,Ontario,50,0.12,6,0,0,0,3
2012,19,Ontario,56,0.07,6,0,0,0,3
2012,20,Ontario,58,0.02,4,0,0,0,3
2012,21,Ontario,69,0.01,6,0,0,0,5
2012,22,Ontario,64,0.09,8,0,0,0,3
2012,23,Ontario,63,0.03,6,1,0,0,6
2012,24,Ontario,67,0.08,6,0,0,0,4
2012,25,Ontario,76,0.17,6,0,0,2,7
2012,26,Ontario,70,0.04,7,0,0,6,10
2012,27,Ontario,75,0.04,5,3,1,10,39
2012,28,Ontario,73,0.02,5,5,3,19,24
2012,29,Ontario,75,0.06,6,9,1,30,19
2012,30,Ontario,72,0.38,6,14,2,89,17
2012,31,Ontario,73,0.16,4,23,1,162,77
2012,32,Ontario,70,0.14,6,44,1,249,46
2012,33,Ontario,68,0.05,4,44,8,312,64
2012,34,Ontario,67,0,4,38,4,375,83
2012,35,Ontario,70,0.15,6,26,0,409,100
2012,36,Ontario,69,0.56,4,25,0,434,79
2012,37,Ontario,61,0.03,5,17,2,454,37
2012,38,Ontario,57,0.16,5,3,4,462,23
2012,39,Ontario,53,0,6,2,6,462,24
2012,40,Ontario,57,0.03,5,3,0,464,18
2012,41,Ontario,42,0.04,5,1,0,464,10
2015,17,Saskatchewan,50,0,10,0,0,0,6
2015,18,Saskatchewan,46,0,11,0,0,0,12
2015,19,Saskatchewan,46,0,9,0,0,0,6
2015,20,Saskatchewan,53,0,8,0,0,0,6
2015,21,Saskatchewan,56,0,8,0,0,2,9
2015,22,Saskatchewan,60,0,10,0,0,0,9
2015,23,Saskatchewan,64,0,10,0,0,3,9
2015,24,Saskatchewan,57,0,8,0,0,3,12
2015,25,Saskatchewan,65,0,7,0,0,10,31
2015,26,Saskatchewan,70,0,6,0,0,13,15
2015,27,Saskatchewan,66,0,9,0,0,16,13
2015,28,Saskatchewan,67,0,8,0,0,40,15
2015,29,Saskatchewan,68,0,10,0,0,47,16
2015,30,Saskatchewan,63,0.02,9,0,0,69,43
2015,31,Saskatchewan,63,0,8,0,0,67,16
2015,32,Saskatchewan,70,0,8,0,0,80,28
2015,33,Saskatchewan,58,0,8,0,0,94,38
2015,34,Saskatchewan,62,0,8,0,0,42,21
2015,35,Saskatchewan,61,0,10,0,1,41,14
2015,36,Saskatchewan,53,0,8,0,0,0,9
2015,37,Saskatchewan,52,0,8,0,0,0,5
2015,38,Saskatchewan,54,0,10,0,0,0,5
2015,39,Saskatchewan,48,0,8,0,0,0,5
2015,40,Saskatchewan,48,0,9,0,0,0,8
2015,41,Saskatchewan,44,0,11,0,0,0,5
2014,17,Saskatchewan,40,0,12,0,0,0,6
2014,18,Saskatchewan,41,0,10,0,0,0,6
2014,19,Saskatchewan,41,0,9,0,0,0,6
2014,20,Saskatchewan,45,0,7,0,0,0,6
2014,21,Saskatchewan,59,0,10,0,0,0,13
2014,22,Saskatchewan,57,0,11,0,0,0,20
2014,23,Saskatchewan,55,0,8,0,0,0,17
2014,24,Saskatchewan,53,0,10,0,0,0,13
2014,25,Saskatchewan,57,0,10,0,0,0,7
2014,26,Saskatchewan,63,0,8,0,0,0,21
2014,27,Saskatchewan,66,0,11,0,0,0,26
2014,28,Saskatchewan,65,0,10,0,0,0,69
2014,29,Saskatchewan,64,0,9,0,0,0,65
2014,30,Saskatchewan,63,0,9,0,0,1,60
2014,31,Saskatchewan,67,0,6,0,0,1,36
2014,32,Saskatchewan,69,0,6,0,2,2,47
2014,33,Saskatchewan,67,0,7,0,0,9,67
2014,34,Saskatchewan,64,0,8,0,0,19,45
2014,35,Saskatchewan,58,0,9,0,0,20,34
2014,36,Saskatchewan,56,0,8,0,0,20,13
2014,37,Saskatchewan,46,0,9,0,0,20,19
2014,38,Saskatchewan,55,0,8,0,0,20,6
2014,39,Saskatchewan,61,0,9,0,0,20,16
2014,40,Saskatchewan,44,0,12,0,0,20,12
2014,41,Saskatchewan,45,0,9,0,0,20,6
2013,17,Saskatchewan,34,0,10,0,0,0,10
2013,18,Saskatchewan,40,0,12,0,0,0,14
2013,19,Saskatchewan,50,0,12,0,0,0,14
2013,20,Saskatchewan,59,0,9,0,0,0,7
2013,21,Saskatchewan,57,0,13,0,0,0,7
2013,22,Saskatchewan,60,0,9,0,0,0,14
2013,23,Saskatchewan,57,0,9,0,0,0,21
2013,24,Saskatchewan,57,0,10,0,0,0,20
2013,25,Saskatchewan,61,0,10,0,0,0,14
2013,26,Saskatchewan,64,0,7,0,0,0,41
2013,27,Saskatchewan,69,0,7,0,0,0,61
2013,28,Saskatchewan,65,0,8,0,0,1,65
2013,29,Saskatchewan,62,0,9,0,3,1,81
2013,30,Saskatchewan,60,0,9,0,1,3,75
2013,31,Saskatchewan,59,0,8,0,2,3,33
2013,32,Saskatchewan,60,0,6,0,1,18,44
2013,33,Saskatchewan,69,0,8,0,0,29,75
2013,34,Saskatchewan,66,0,8,1,1,29,60
2013,35,Saskatchewan,69,0,8,3,0,36,24
2013,36,Saskatchewan,67,0,7,1,0,40,21
2013,37,Saskatchewan,62,0,9,0,0,40,26
2013,38,Saskatchewan,57,0,10,1,2,40,32
2013,39,Saskatchewan,51,0,9,0,1,40,13
2013,40,Saskatchewan,45,0,11,0,0,40,29
2013,41,Saskatchewan,46,0,10,0,0,40,10
2012,17,Saskatchewan,44,0,13,0,0,0,24
2012,18,Saskatchewan,46,0,12,0,0,0,16
2012,19,Saskatchewan,51,0,13,0,0,0,16
2012,20,Saskatchewan,54,0,12,0,0,0,9
2012,21,Saskatchewan,48,0,11,0,0,0,17
2012,22,Saskatchewan,53,0,9,0,0,0,16
2012,23,Saskatchewan,61,0,13,0,0,0,8
2012,24,Saskatchewan,56,0,11,0,0,0,16
2012,25,Saskatchewan,58,0,7,0,0,0,25
2012,26,Saskatchewan,64,0,12,0,0,0,22
2012,27,Saskatchewan,65,0,9,0,0,0,23
2012,28,Saskatchewan,71,0,7,0,1,0,67
2012,29,Saskatchewan,67,0,10,0,0,0,34
2012,30,Saskatchewan,67,0,8,0,0,0,28
2012,31,Saskatchewan,64,0,8,0,0,0,59
2012,32,Saskatchewan,68,0,8,0,0,3,58
2012,33,Saskatchewan,59,0,8,2,0,4,34
2012,34,Saskatchewan,65,0,9,1,0,6,100
2012,35,Saskatchewan,64,0,9,0,0,6,49
2012,36,Saskatchewan,55,0,11,3,0,6,41
2012,37,Saskatchewan,58,0,13,0,0,6,16
2012,38,Saskatchewan,50,0,8,3,0,6,19
2012,39,Saskatchewan,55,0,6,0,0,6,15
2012,40,Saskatchewan,42,0,10,0,0,6,11
2012,41,Saskatchewan,36,0,8,0,0,6,7
First I produced this plot
But I did that in the most brute force way imaginable
#split out each year
cases2015 <- subset(mosquitoes, mosquitoes$Years==2015)
cases2014 <- subset(mosquitoes, mosquitoes$Years==2014)
cases2013 <- subset(mosquitoes, mosquitoes$Years==2013)
cases2012 <- subset(mosquitoes, mosquitoes$Years==2012)
#get the sums by week
aggregate2015 <- aggregate(cases2015$Number.of.cases, by=list(Weeks=cases2015$Weeks), FUN=sum)
aggregate2014 <- aggregate(cases2014$Number.of.cases, by=list(Weeks=cases2014$Weeks), FUN=sum)
aggregate2013 <- aggregate(cases2013$Number.of.cases, by=list(Weeks=cases2013$Weeks), FUN=sum)
aggregate2012 <- aggregate(cases2012$Number.of.cases, by=list(Weeks=cases2012$Weeks), FUN=sum)
#put the sums back together into a dataframe
aggregateSums <- aggregate2012
aggregateSums <- cbind(aggregateSums, aggregate2013[,2])
aggregateSums <- cbind(aggregateSums, aggregate2014[,2])
aggregateSums <- cbind(aggregateSums, aggregate2015[,2])
#give the columns useful names
colnames(aggregateSums) <- c("Weeks","Cases.2012","Cases.2013","Cases.2014","Cases.2015")
#base R plot
#plot the first set of points
plot(x=aggregateSums$Weeks,y=aggregateSums$Cases.2012,pch=16,col="Red",main="West Nile Cases",xlab="Week",ylab="Number of Cases")
#add additional years
points(x=aggregateSums$Weeks,y=aggregateSums$Cases.2013,pch=15,col="Blue")
points(x=aggregateSums$Weeks,y=aggregateSums$Cases.2014,pch=14,col="Orange")
points(x=aggregateSums$Weeks,y=aggregateSums$Cases.2015,pch=13,col="Brown")
#add the connecting lines
lines(x=aggregateSums$Weeks,y=aggregateSums$Cases.2012,col="Red")
lines(x=aggregateSums$Weeks,y=aggregateSums$Cases.2013,col="Blue")
lines(x=aggregateSums$Weeks,y=aggregateSums$Cases.2014,col="Orange")
lines(x=aggregateSums$Weeks,y=aggregateSums$Cases.2015,col="Brown")
#click to place legend
legend(locator(1),c("2012","2013","2014","2015"),pch=c(16,15,14,13), col=c("Red","Blue","Orange","Brown"))
So surely there has to be a more efficient way to get there.
My next step is to produce the same plot but for just one province at a time. I don't want to have to go through the above 6 times...
I'm opening to accomplishing this via ggplot. If possible, I'd like to do it without resorting to additional packages (like plyr) as I'm trying to learn the base functionality for manipulating data.
Just to close the loop after Biranjan's answer...
mosq2 <- mosquitoes %>%
select(Years,Weeks,Province,Number.of.cases) %>%
group_by(Years,Weeks,Province) %>%
summarise(sum_case=sum(Number.of.cases))
ggplot(data=mosq2, aes(x=as.factor(Weeks),y=sum_case,color=as.factor(Years))) +
geom_point(aes(shape=as.factor(Years))) +
geom_line(aes(group=as.factor(Years))) +
labs(title="West Nile Cases", x="weeks", y="Number of cases") +
theme(legend.title=element_blank()) +
facet_wrap(~Province,ncol=3) +
scale_x_discrete(breaks=c(17,30,41))
Turned out quite nicely
ggplot(data=data1, aes(x=as.factor(Weeks),y=sum_case,color=as.factor(Years)))+
geom_point(aes(shape=as.factor(Years)))+
geom_line(aes(group=as.factor(Years)))+
labs(title="West Nile cases",x="weeks",y="Number of cases")+
theme(legend.title=element_blank())
Update:
I had too few points in my simulation so it rendered fine so that was the problem. I could't find a way to plot just using ggplot. The same code works if "dplyr" is used first and variable name edited accordingly. I know it is not what you are looking for, sorry to disappoint you.
library(dplyr)
data1 <- data %>%
select(Years,Weeks,Number.of.cases) %>%
group_by(Years,Weeks) %>%
summarise(sum_case=sum(Number.of.cases))

Resources