Este es mi MWE:
\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label First Second Third
Yes 0.1 0.3 0.3
No 0.9 0.7 0.7
}\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={\datatable}{Label} % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable}; % Plot the "First" column against the data index
\addplot [fill=green!70!blue] table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}
Este script genera un gráfico en el que el eje y corresponde a los valores Sí/No para las columnas.Primero,Segundo, yTercero. ¿Cómo cambio el script para que el eje y corresponda a las columnas (es decir,Primero,Segundo, yTercero)? Necesito representar horizontalmente la distribución Sí/No para una columna específica.
Respuesta1
Encontré una solución portransponiendo la tablay modificando el script de la siguiente manera:
\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label First Second Third
Yes 0.1 0.3 0.3
No 0.9 0.7 0.7
}\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
]
\addplot [fill=green!70!blue] table [x=Yes, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!blue] table [x=No, y expr=\coordindex] {\datatabletransposed};
\end{axis}
\end{tikzpicture}