2
$\begingroup$

I am trying to put together a BarChart and a BoxWhiskerPlot in this form:

Show[BarChart[timesDifference[[2]], 
  ChartLabels -> Placed[timesDifference[[1]], Axis], 
  ChartStyle -> "Pastel", Frame -> True, 
  FrameLabel -> {"days", "Number of Individuals"}, PlotLabel -> name, 
  PlotRange -> All], 
 BoxWhiskerChart[(posList2 - posList1), "Mean", BarOrigin -> Left, 
  ChartStyle -> {{Gray}, {Opacity[0.6]}}, Frame -> True, 
  PlotRange -> {{0, 41}, All}]]

However I got two problems: 1. The graphs are out of phase. I mean, the max and min values of the BoxWhiskerPlot do not overlap those values in the BarChart. How can I make a good overlap? 2. In some graphs the BoxWhiskerPlot is so tiny or just in the edge of the x axes and it is difficult to see it. How can I put it in the center of the final graph? (this plot show how it looks-The grey line over the x axes-)

enter image description here

This is a part of the date for this plot. However, the position of the BoxWhiskerPlot change with the number of date. So, the position of the BoxWhiskerPlot becomes more to the bottom as long as I increased the date amount.

posList1 = {1, 7, 3, 9, 11, 9, 5, 9, 10, 9, 9, 9, 9, 10, 12, 11, 2, 
   10, 12, 12, 13, 12, 11, 15, 13, 13, 13, 14, 15, 13, 15, 14, 14, 15,
    15, 16, 10, 16, 13, 12, 13, 15, 9, 10, 15, 11, 14, 12, 15, 15, 8, 
   16, 12, 16, 16, 15, 13, 15, 17, 18, 18, 14, 13, 15, 17, 18, 17, 17,
    17, 14, 14, 16, 14, 17, 15, 16, 17, 17, 15, 13, 16, 14, 14, 17, 
   18, 16, 13, 14, 13, 19, 18, 18, 16, 16, 15, 14, 12, 14, 18, 12};
posList2 = {9, 12, 12, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16,
    16, 17, 17, 17, 17, 17, 17, 17, 17, 16, 17, 15, 18, 16, 18, 18, 
   18, 17, 17, 17, 17, 17, 18, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 
   20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
    20, 20, 18, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 
   21, 22, 22};
timesDifference = Tally[(posList2 - posList1) // Sort] // Transpose;
$\endgroup$
  • 1
    $\begingroup$ Gotta share your data and definitions too, otherwise we can't run your code. $\endgroup$ – MarcoB Apr 28 at 13:30
4
$\begingroup$

It is more convenient to use Histogram instead of BarChart so that the horizontal axis scales are the same for both Histogram and BoxWhiskerChart:

Show[Histogram[posList2 - posList1,
  ChartLabels -> Placed[timesDifference[[1]], Axis], 
  ChartStyle -> "Pastel", Frame -> True, 
  FrameLabel -> {"days", "Number of Individuals"}, 
  PlotRange -> {All, {-2, All}}], 
 MapAt[GeometricTransformation[#, TranslationTransform[{0, -1.67}]] &,
   BoxWhiskerChart[posList2 - posList1, "Mean", BarOrigin -> Left, 
   ChartStyle -> {{Gray}, {Opacity[0.6]}}, Frame -> True, 
   PlotRange -> {{0, 41}, All}], {1}], FrameTicks -> All]

enter image description here

Show[Histogram[posList2 - posList1, ChartStyle -> "Pastel", 
  Frame -> True, FrameLabel -> {"days", "Number of Individuals"}, 
  PlotRange -> {All, {-4, All}}], 
 MapAt[GeometricTransformation[#, 
    ScalingTransform[{1, 4}]@*TranslationTransform[{0, -1.2}]] &, 
  BoxWhiskerChart[posList2 - posList1, "Mean", BarOrigin -> Left, 
   ChartStyle -> {{Gray}, {Opacity[0.6]}}, Frame -> True, 
   PlotRange -> {{0, 41}, All}], {1}]]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.