I have following code in Latex. Which plots only one data series (data2). I would like to plot staked bar plot inside table for both data1 and data2 with different colours.
Any ideas.?
Many thanks.
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{pgfplotstable}
\usepackage{filecontents}
% The data
\begin{filecontents}{data.txt}
accession,data1,data2
C1,150708.4564,481.0388003
C2,49652.53112,275.2190163
C3,37379.1284,58.85806921
C4,34165.85698,26.06571636
C5,30856.19158,35.96802428
C6,15204.22768,26.71594573
\end{filecontents}
\pgfplotstableread[col sep=comma]{data.txt}\data
\newcommand{\errplot}{%
\begin{tikzpicture}[trim axis right]
\begin{axis}[y=-\baselineskip,
scale only axis,
width=5cm,
enlarge y limits={abs=0.5},
axis y line*=middle,
ytick=\empty,
axis x line*=bottom,
xbar,
bar width=1.5ex,
xmin=0,
visualization depends on=x \as \rawx,
nodes near coords,
every node near coord/.style={
anchor=east,
shift={(axis direction cs:-\rawx,0)}
}
]
%
\addplot [draw=black, fill=red]
table [x=data2,y expr=\coordindex]{\data};
\end{axis}
\end{tikzpicture}%
}
\begin{document}
% Get number of rows in datafile
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval
% Print the table
\pgfplotstabletypeset[columns={accession,data1,data2},
% Booktabs rules
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=[3ex]\bottomrule},
% Set header name
columns/accession/.style={string type,column type=l,column name=accession},
columns/data1/.style={string type,column type=l,column name=data1},
columns/data2/.style={
column name={Data2},
assign cell content/.code={% use \multirow for Z column:
\ifnum\pgfplotstablerow=0
\pgfkeyssetvalue{/pgfplots/table/@cell content}
{\multirow{\numberofrows}{6.5cm}{\errplot}}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
},
]{\data}
\end{document}