¿Cómo seleccionar un rango de datos en tikz-pgf?

¿Cómo seleccionar un rango de datos en tikz-pgf?

Este es un subconjunto de mi tabla que quiero usar para crear un gráfico de barras apiladas:

ingrese la descripción de la imagen aquí

¿Es posible seleccionar las columnas de la A a la F para las dos primeras filas y luego seleccionar la columna G para las otras filas para crear un gráfico de barras apiladas?

Este es mi MWE:

\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label A B C D E F G
Yes 0.24    0.92    0.52    0.96    0.52    0.24 nan
No 0.76 0.08    0.48    0.04    0.48    0.76 nan
High nan nan nan nan nan nan 0.08
Medium nan nan nan nan nan nan 0.4
Low nan nan nan nan nan nan 0.52
}\datatable

\pgfplotstabletranspose[string type, colnames from=Label, input colnames to=Label]\datatabletransposed{\datatable}

\begin{axis}[
    xbar stacked, % Stacked horizontal bars
    xmin=0, % Start x axis at 0
    ytick=data, % Use as many tick labels as y coordinates
    yticklabels from table={\datatabletransposed}{Label}, % Get the labels from the Label column of the \datatable
    legend style={at={(0,0)}, anchor=north east,at={(axis description cs:0,-0.1)}}]
]
\addplot [fill=green!70!blue] table [x=Yes, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!white] table [x=No, y expr=\coordindex] {\datatabletransposed};
\legend{Yes, No}
\end{axis}
\end{tikzpicture}

Respuesta1

Usar nan o NaN no es una buena idea para datos faltantes, al menos para un gráfico de barras apiladas.

\documentclass[multi=tikzpicture]{standalone}
\usepackage{pgfplots,pgfplotstable}
\begin{document}


\pgfplotstableread{% Read the data into a table macro
Label A B C D E F G
Yes 0.24    0.92    0.52    0.96    0.52    0.24 0
No 0.76 0.08    0.48    0.04    0.48    0.76 0
High 0 0 0 0 0 0 0.08
Medium 0 0 0 0 0 0 0.4
Low 0 0 0 0 0 0 0.52
}\datatable

\pgfplotstabletranspose[string type, colnames from=Label, input colnames to=Label]\datatabletransposed{\datatable}

%\begin{tikzpicture}
%\node{\pgfplotstabletypeset[string type]\datatabletransposed};
%\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
    xbar stacked, % Stacked horizontal bars
    xmin=0, % Start x axis at 0
    ytick=data, % Use as many tick labels as y coordinates
    yticklabels from table={\datatabletransposed}{Label}, % Get the labels from the Label column of the \datatable
    legend style={at={(0,0)}, anchor=north east,at={(axis description cs:0,-0.1)}}]
\addplot [fill=green!70!blue] table [x=Yes, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!white] table [x=No, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=green!70!blue] table [x=High, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!white] table [x=Medium, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=yellow] table [x=Low, y expr=\coordindex] {\datatabletransposed};
\legend{Yes, No}
\end{axis}
\end{tikzpicture}

\end{document} 

manifestación

información relacionada