Как поменять местами строку/столбец в столбчатой ​​диаграмме с накоплением

Как поменять местами строку/столбец в столбчатой ​​диаграмме с накоплением

Это мой 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}

Этот скрипт создает диаграмму, в которой ось Y соответствует значениям Да/Нет для столбцов.Первый,Второй, иТретий. Как изменить скрипт так, чтобы ось Y соответствовала столбцам (т.е.Первый,Второй, иТретий)? Мне нужно отобразить распределение «Да/Нет» для определенного столбца по горизонтали.

решение1

Я нашел решениетранспонирование таблицыи изменим скрипт следующим образом:

\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}

Связанный контент