I have a histogram like the one presented here by @kglr
(Combine BarChart and TimeLinePlot). For the sake of brevity, I excluded the issue with timelineplot
:
(*some data preprocessing:*)
data = {{2000, 2, 0, 6, 4}, {2001, 0, 0, 8, 14}, {2002, 1, 0, 10,
13}, {2003, 4, 0, 8, 9}, {2004, 3, 0, 13, 11}, {2005, 0, 1, 9,
7}, {2006, 3, 2, 2, 8}, {2007, 0, 0, 11, 7}, {2008, 6, 1, 8,
8}, {2009, 2, 5, 2, 7}, {2010, 4, 2, 11, 14}, {2011, 4, 0, 5,
11}, {2012, 6, 2, 11, 10}, {2013, 5, 0, 8, 11}, {2014, 1, 3, 10,
7}, {2015, 0, 0, 9, 6}};
makeshares[{year_, amb_, neg_, neu_, pos_}] :=
Module[{total, shares}, total = Total[{amb, neg, neu, pos}];
shares = {year, pos/total // N, neu/total // N, amb/total // N,
neg/total // N}];
data2 = makeshares[#] & /@ data;
data2shares =
WeightedData[data2[[All, {1}]], data2[[All, #]]] & /@ {2, 3, 4, 5};
The histogram
data2histogramm =
DateHistogram[data2shares, "Year", ChartLayout -> "Stacked",
ChartStyle -> {Opacity[0.9, Darker[Blue]], Opacity[0.7, Pink],
Opacity[0.7, Orange], Opacity[0.9, Darker[Yellow]]},
ImageSize -> {700, 500},
Ticks -> {AbsoluteTime /@
Thread[{tradeevaluationsdata2[[All, 1]], 7, 15}], Automatic},
Frame -> {{True, False}, {True, False}},
DateTicksFormat -> {"Year"}, ChartBaseStyle -> Opacity[1],
PlotRangeClipping -> False,
ImagePadding -> {{Automatic, 50}, {140, 10}}]
yields
Now, inspired by a custom ticks function presented here: How to rotate TickLabels in DateListPlot, I tried to rotate the ticks:
rotatedDateTicksF[n_] :=
MapAt[Rotate[#, Pi/2] &,
System`DateListPlotDump`DateTicks[{##}, n, {"Year"}], {All, 2}] &;
the new histogram
data2histogramm2 =
DateHistogram[data2shares, "Year", ChartLayout -> "Stacked",
ChartStyle -> {Opacity[0.9, Darker[Blue]], Opacity[0.7, Pink],
Opacity[0.7, Orange], Opacity[0.9, Darker[Yellow]]},
ImageSize -> {700, 500},
FrameTicks -> {{Automatic,
Automatic}, {rotatedDateTicksF[15][{2000},
DatePlus[{2000}, {15, "Year"}]], Automatic}},
Frame -> {{True, False}, {True, False}},
ChartBaseStyle -> Opacity[1], PlotRangeClipping -> False,
ImagePadding -> {{Automatic, 50}, {120, 10}}]
Unfortunately, the ticks are on the left edge below each bar, so how can I put them into the middle (below the bar)?