Dear i try to generate an histogram / barplot
result.csv:
overlap,hit,organism
100,274,Unknowns
100,228,Coccomyxa subellipsoidea
100,11,Eukaryota
-500,153,Unknowns
-500,145,Coccomyxa subellipsoidea
-500,7,Eukaryota
-1000,118,Unknowns
-1000,108,Coccomyxa subellipsoidea
-1000,4,cellular organisms
-2000,74,Coccomyxa subellipsoide
-2000,72,Unknowns
-2000,4,Viridiplantae
-4000,51,Unknowns
-4000,42,Coccomyxa subellipsoidea
-4000,2,Eukaryota
-8000,26,Coccomyxa subellipsoidea
-8000,25,Unknowns
-8000,1,Eukaryota
-16000,14,Coccomyxa subellipsoidea
-16000,13,Unknowns
-16000,1,cellular organisms
As you can see we can group data in 7 category using overlap :
100, -500, -1000, -2000, -4000, -8000, -16000
\documentclass[table]{beamer}
\usepackage[american]{babel}
\usepackage{etex}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{textcomp}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\pgfplotsset{
compat = newest,
table/col sep = comma
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\pgfplotstableread{result.csv}\table
\centering
\begin{axis}[
visualization depends on={value \thisrow{organism} \as \labela},
visualization depends on={value \thisrow{hit} \as \labelb},
ybar,
height = 6cm,
width = 10cm,
enlarge y limits = false,
axis lines* = left,
ymin = 0,
ymax = 300,
xmin = -17000,
xmax = 600,
legend style = {
at = {(0.5,-0.2)},
anchor = north,
legend columns = -1
},
xtick = data,
scaled y ticks = false,
y tick label style = {/pgf/number format/fixed,/pgf/number format/1000 sep = \thinspace},
xticklabels from table= \table{overlap},
nodes near coords={\labela/\pgfmathprintnumber\labelb},
every node near coord/.append style={ anchor=mid west, rotate=80 }
]
\foreach \i in {1,2,...,21}{
\addplot table[ x index=\i, y index=1 ] \table;
}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
But i fail to plot correctly, current code give an error:
! Package PGF Math Error: Could not parse input 'Unknowns' as a floating point
number, sorry. The unreadable part was near 'Unknowns'.
Thanks for your help
\i
to choose which column to use for the x values. I'm not exactly sure what you're trying to achieve: Do you want to add one plot for each row of your data? That won't work as intended, because you'll either get huge gaps between your bars, or they will all lie on top of each other (depending on where you put theybar
keyword). Could you explain in a bit more detail what kind of output you're going for (maybe draw a mockup?), and could you remove all the bits of code that aren't relevant for the problem?