I have a time series dataset I'm trying to plot by Year:
{{DateObject[{1991, 7}], 3.52659}, {DateObject[{1991, 8}],
3.18089}, {DateObject[{1991, 9}], 3.25222}, {DateObject[{1991, 10}],
3.611}, {DateObject[{1991, 11}], 3.56587}, {DateObject[{1991, 12}],
4.30637}, {DateObject[{1992, 1}], 5.08834}, {DateObject[{1992, 2}],
2.81452}, {DateObject[{1992, 3}], 2.98581}, {DateObject[{1992, 4}],
3.20478}}
...
I plotted it this way DateListPlot[data]
:
Now I'm trying to plot it by Year, following the example from here: http://www.wolfram.com/mathematica/new-in-10/semantic-data-import/analyze-retail-sales-data.html
But instead of grouping by City
, I'm grouping by Year
:
dataByYear =
GroupBy[data, (DateValue[#[[1]],
"Year"]) & -> ({DateValue[#[[1]], "MonthName"], #[[2]]} &)];
But when I try to plot it I get the following error message:
DateListPlot[dataByYear[[All]], PlotLegends -> Keys[dataByYear]]
<|1991->{{July ,3.526591`},{August ,3.180891`},{September ,3.252221`},{October ,3.611003`},{November ,3.565869`},{December ,4.306371`}},<<16>>,2008->{{January ,29.665356`},{February ,21.654285`},{March ,18.264945`},{April ,23.107677`},{May ,22.91251`},{June ,19.43174`}}|> is not a valid dataset or list of datasets. >>
I checked the dataset returned by the GroupBy
from Wolfram's example, and they do look very similar. The only difference seems to be the Keys
are the name of the cities and in my case the Keys
are the Years
.
What's wrong with my code?
Edit:
I abandoned the previous approach and decide to try plotting every year separately and them "joining" them (Sorry, I don't know the proper Mathematica term for this). This is how far I've managed to go:
Show[Table[DateListPlot[dataByYear[i]], {i, 1992, 2000}], PlotRange -> Automatic]
Now how do I label and color each year in order to look something like the image below?
Any help would be much appreciated!
DateListPlot[dateByGroup[1992]]
it works fine. It's the same data. $\endgroup$