I have a fairly complex sort of BarChart that I want to overlay with other graphics. For concreteness, let's assume that I want to overlay a LinePlot. In doing so, I found this answer quite helpful, but my chart has some additional wrinkles which complicate things. First, let's invent some data:
data = {Association["a" -> 0.7037417451289036, "b" -> 0.503687396357559, "c" -> 0.8305301936239331, "d" -> 0.23466296631845518], Association[ "a" -> 0.08369185073518004, "b" -> 0.5808357340946317, "c" -> 1.873919922991976, "d" -> 1.3981710526525974], Association["a" -> 1.6327509774236528, "b" -> 1.3925276568460028, "c" -> 1.1036001759467897, "d" -> 1.0264775292307071], Association["a" -> 3.218464871800018, "b" -> 0.6400499501591295, "c" -> 0.4775621030459698, "d" -> 2.375619997842695], Association["a" -> 3.160797696474269, "b" -> 0.36822672048523586, "c" -> 3.862723785325967, "d" -> 0.41766552167593396]}; Then I'll whip up a BarChart:
bars = BarChart[data, ChartLegends -> Automatic, PlotRange -> {Automatic, Automatic}] Now for the ListPlot, using the DataRange trick suggested by that linked answer.
means = Mean /@ data; lines = ListPlot[means, Joined -> True, PlotStyle -> Black, DataRange -> {2.5, 2.5 + 4*4}] Now I can Show the two together:
Show[bars, lines, ImagePadding -> {{10, 10}, {10, 10}}] As you can see, it's almost, but not quite, right. Evidently the spacing between the groups throws things off, but I'm not entirely sure how much, in part because I'm not sure how much spacing there is between bars. It's complicated by the fact that there are two different sorts of spacing, one within groups of bars, and one between bars, and the two seem to affect the $x$-coördinates of the bars in different ways. I could set BarSpacings to {None, None}, but that looks ugly.
Is there a better way? Or a simple way of understanding how bars are spaced when they're divided into groups?







