Sometimes it is useful to present the coefficients of a regression with accompanying confidence intervals as a dot-and-whisker plot. See here for a motivation of this approach and some examples of what I am trying to achieve based on an R package dotwhisker designed to produce these plots. Here is an example from the linked R vignette:
I would like to replicate similar dot-and-whisker plots in PGFPLOTS.
PGFPLOTS supports box-and-whisker plots natively -- here is an example. A full description of the box-and-whisker feature of PGF is in section 5.12.1 of manual version 1.16.
Here is my best attempt:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={1,2,3},
yticklabels={Group A, Group B, Group C},
]
\addplot+ [
boxplot prepared={
lower whisker=0.35,
% lower quartile=,
median=0.6,
% upper quartile=,
upper whisker=0.85,
},
]
coordinates {};
\addplot+ [
boxplot prepared={
lower whisker=0.55,
% lower quartile=,
median=0.70,
% upper quartile=,
upper whisker=0.85,
},
]
coordinates {};
\addplot+ [
boxplot prepared={
lower whisker=0.85,
% lower quartile=,
median=0.9,
% upper quartile=,
upper whisker=0.95,
},
]
coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}
There are several problems with my attempt:
- I am adapting the box and whisker feature to represent something that is not a box whisker. This is perhaps the wrong way to approach things. My kludge treats the median as the coefficient estimate, and treats the upper and lower whiskers as the upper and lower confidence intervals. I comment out the quartiles as I do not have an equivalent for these, and I do not want the box.
- Unlike the
Rpackagedotwhister, the graphics are not clear -- having vertical lines puts too much emphasis on the confidence bounds relative to the coefficient point estimate. - It is not scalable. I would like to analyse 50 groups. Everytime I update my data I do not want to manually update the box plot
entries in
PGFPLOTS. I would prefer to be able to read from a.csvcontaining 50 rows for each group and four columns: group name, coefficient estimate, upper confidence interval, lower confidence interval.
Here is some randomly generated data (upper and lower are symmetric around point_est):
\begin{filecontents*}{dotwhisker.csv}
group,point_est,upper,lower
SCBQD6600C,0.318940138,0.782642805,-0.144762529
GHECK1046A,0.541614386,1.425115639,-0.341886867
ICOOO3242S,0.662666177,1.143455809,0.181876544
PHOVQ7028A,0.148145345,0.239989182,0.056301508
HSJEK0588Y,0.564368703,0.997673282,0.131064125
CYVFG8255L,0.575908384,1.288811424,-0.136994656
ZDYRJ3242S,0.413789006,0.639376662,0.18820135
PXQSX1684J,0.418005222,0.974470232,-0.138459788
VTCRK0417U,0.4153322,1.020437688,-0.189773288
WSYWC4669M,0.366494326,0.756315385,-0.023326734
BZPKZ2934L,0.428421095,0.792023892,0.064818298
EGIPR1094A,0.350242033,0.598746704,0.101737362
PQTFK6203U,0.383561916,0.660697282,0.10642655
UYLGX7811M,0.509668823,1.037205877,-0.017868231
ICEHA2251J,0.643924109,1.452395674,-0.164547457
\end{filecontents*}



tikzDevicepackage and would rather avoid that approach applied to the above R package for dot-whisker plots. I want to plot directly in PGFplots based on coefficient estimate and standard error. – Sav-econ Nov 23 '19 at 17:580.55,0.70and0.85(or0.55and0.15for symmetric whiskers) from a csv file to create a series of\addplot+ [ boxplot prepared={ lower whisker=0.55, % lower quartile=, median=0.70, % upper quartile=, upper whisker=0.85, }, ] coordinates {};which use these values, the answer is of course affirmative. – Nov 24 '19 at 12:57.csvwhere each row is a separate group, and there are four columns 1. group name 2. "median" 3. "upper whisker" 4. "lower whisker". I use quotations as this is not what is being represented statistically, but it is how we would interpret in terms of the box and whisker plot semantics. However, I say this is a start because I'd then be unsatisfied with the vertical line representations which are more confusing than having dots, seeRdotwhiskerpackage. Hence an alternative to the box whisker package in PGF might be more viable. – Sav-econ Nov 24 '19 at 13:03