# Create a ybar interval from given bar widths

I am collecting data using the NASA Task Load Index, which gives 6 scales and has a weight associated with each scale. I am trying to plot the mean value for each scale using a ybar interval graph, whereby the width of each bar is set by the weight for the corresponding scale, similar to the picture below taken from the manual.

I have managed to create an additional column that should give me the right interval data (see table), but the bar width doesn't look correct, nor am I able to then use the symbolic x coords as labels for the bars.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

Scale    Mean  Weight
MD      53.25    3.50
PD      12.22    1.50
TD      18.46    1.75
FR      45.75    3.00
OP      59.18    2.45
EF      22.15    2.80
Overall 38.175   2.50
}{\tlxweightedratings}

\pgfplotstabletypeset[
columns/Scale/.style={string type},
create on use/Interval/.style={
create col/expr={\pgfmathaccuma + \thisrow{Weight}}},
columns={Scale, Mean, Weight, Interval},
]{\tlxweightedratings}

\begin{tikzpicture}
\begin{axis}[ybar interval, xtick=data,
nodes near coords,
%symbolic x coords={MD, PD, TD, FR, OP, EF, Overall},
]
create on use/Interval/.style={
create col/expr={\pgfmathaccuma + \thisrow{Weight}}},
] {\tlxweightedratings};
\end{axis}
\end{tikzpicture}
\end{document}

-

The ybar interval plot style uses the x value of the current data point as the left edge of the column, and the x value of the next data point as the right edge of the column. With your method of calculating the Interval, the first column starts at 3.5 and stretches to 5, so it has a width of 1.5. You want it to start at 0 and stretch to 3.5, however, so you should change your code to use \prevrow instead of \thisrow. You also need to add a dummy data row to your table, so the width of the last column can be calculated as well.

You don't actually want symbolic x coordinates, since they're always equally spaced. Simply use xticklabels={MD, ... to set the labels.

nodes near coordinates don't currently work satisfactorily with ybar interval, since they're always positioned above the start of the columns, not their centers.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

Scale    Mean  Weight
MD      53.25    3.50
PD      12.22    1.50
TD      18.46    1.75
FR      45.75    3.00
OP      59.18    2.45
EF      22.15    2.80
Overall 38.175   2.50
Dummy    0       0
}{\tlxweightedratings}

\pgfplotstabletypeset[
columns/Scale/.style={string type},
create on use/Interval/.style={
create col/expr={\pgfmathaccuma + \thisrow{Weight}}},
columns={Scale, Mean, Weight, Interval},
]{\tlxweightedratings}

\begin{tikzpicture}
\begin{axis}[
ymin=0,
ybar interval, xtick=data,
xticklabels={MD, PD, TD, FR, OP, EF, Overall},
]