5
$\begingroup$

I think this is called a caterpillar plot. The dot is the mean and the lines represent a 95% confidence interval.

On the x axis there are several different test cycles, the red line is the true value.

enter image description here

$\endgroup$
  • $\begingroup$ There's also BoxWhiskerChart $\endgroup$ – Jens Oct 13 '14 at 7:19
  • $\begingroup$ @Jens I know, but a Boxplot indicates the median not the mean. $\endgroup$ – spore234 Oct 13 '14 at 7:26
  • $\begingroup$ Related: (15671) $\endgroup$ – Mr.Wizard Oct 13 '14 at 17:45
7
$\begingroup$

You can use ErrorListPlot as described in: How to : Add Error Bars to Charts and Plots.
(This might be considered "easily found" however I don't believe "caterpillar plot" would find it.)

The first example from the documentation:

Needs["ErrorBarPlots`"]

ErrorListPlot[Table[{i, RandomReal[{0.2, 1}]}, {i, 10}]]

enter image description here


By the way if you find that the error bars are being cut off by the edges of the plot you can use Show with a PlotRange of All:

ErrorListPlot[Table[{i, RandomReal[{1, 3}]}, {i, 10}]];

Show[%, PlotRange -> All]

enter image description here

The fact that the error bars are not taken into consideration for the plot range in ErrorListPlot itself might be considered a bug.

$\endgroup$
9
$\begingroup$

Here is a cheat using BoxWhiskerChart. The error bars are quantiles (0.05, 0.95) and not symmetric confidence interval. It is not ideal wrt placement of mean marker.

Using:

rv = RandomVariate[NormalDistribution[10, 3], {20, 10}];
BoxWhiskerChart[rv, {{"MeanMarker", Style[\[FilledSmallCircle], 20], 
   Blue}}, Method -> {"BoxRange" -> (Quantile[#, {0.05, 0.5, 0.5, 0.5,
         0.95}, {{1, -1}, {0, 1}}] &)}, ChartStyle -> White, 
 GridLines -> {None, {{4, Dashed}, 10, {16, Dashed}}}, 
 GridLinesStyle -> Red]

enter image description here

Here is an example using $\mu \pm 1.96 \sigma/\sqrt{n}$ to illustrate how you can adapt:

fun[d_] := {#1 - 1.96 #2, #3, #3, #3, #1 + 1.96 #2} & @@ {Mean[d], 
   StandardDeviation[d]/Sqrt[Length@d], Median[d]}
BoxWhiskerChart[rv, {{"MeanMarker", Style[\[FilledSmallCircle], 20], 
   Blue}}, Method -> {"BoxRange" -> (fun@# &)}, ChartStyle -> White, 
 GridLines -> {None, {{4, Dashed}, 10, {16, Dashed}}}, 
 GridLinesStyle -> Red]

yielding:

enter image description here

$\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.