3
votes

I made a horizontal histogram by turning the diagram by 270° using the rotate package in LaTex. It is no problem to adjust all the labels and tics, but I did not find a way to rotate the key.

enter image description here

Here is my gnuplot code:

set terminal epslatex  size 16cm, 32cm
set output "stackexchange.tex"
set xrange [-1:8]
set key
set boxwidth 0.95
set style data histograms
set style histogram errorbars
set style fill solid 0.8
set style line 1 lt 1 lc rgb "#0080B0" lw 3
set yrange[600:1100]
unset ytics
set y2tics rotate
set y2label rotate "xyz / abc"
set xtics nomirror rotate scale 0 
plot 'stackexchange.dat' using 2:3:xticlabels(1) ls 1 title 'A', '' using 4:5 ls 1 fill pattern 6 title 'B'

That is how I implement it in LaTex:

\begin{figure}
        \begin{turn}{270}
        \resizebox{!}{0.9\textwidth}{\input{stackexchange}}
        \end{turn}
\end{figure}

This is my datafile:

A     890.1  3.2  789.9 11.7 
B    626.97      20.467      862.8 12.3
C   923.9   5.89  963.8 3.7
D    785.233     15.921     627   2.3
E    903.167     7.94 880.9 1.9
F    863.43      25.237     778.2 4.2
G     909.6 5.370     941   13
H     895.633     40.401    813   11.3
2
gnuplot-tricks.blogspot.de/2009/10/turning-of-histogram.html does it the same way and has a hand-made legend. - Karl
Thanks @Karl. This works, although I still hope for a simpler solution. The adjustment of the key and labels is tedious, especially in a multiplot graph - cps
you could use "set label 'blabla'" together with "set object rectangle..." - PinkFloyd

2 Answers

0
votes

I suppose you can do something like this :

x = 0.5
y = 1000
dx = 0.1
dy = 50
set label 'B' at x,y rotate by 90 offset 0.5,-1
set style rectangle fc ls 3 fs pattern 6 border 3 
set object rectangle from x,y to x+dx,y+dy

I let you set the properties of the style rectangle so it matches your histogram.

0
votes

I guess this is a classical xy-problem. Actually, you want to have a horizontal histogram and since it doesn't exist as direct plotting style in gnuplot you think the solution would be to make a vertical histogram rotate it and now you have the problem of how to rotate the key labels.

I know it would be convenient if there was a horizontal histogram but as far as I know gnuplot 5.4 still doesn't have it. So, you can do it "manually" with the plotting style boxxyerror. This works with gnuplot 5.0 (version at the time of OP's question) and with some small modifications even with older versions. The result below is from wxt terminal, but is should work the same with epslatex terminal.

Code:

### Horizontal grouped histogram
reset session

$Data <<EOD
A    890.1      3.2     789.9   11.7 
B    626.97    20.467   862.8   12.3
C    923.9      5.89    963.8    3.7
D    785.233   15.921   627      2.3
E    903.16     7.94    880.9    1.9
F    863.      25.237   778.2    4.2
G    909.6      5.37    941     13
H    895.6     40.41    813     11.3
EOD

N = 2   # number of boxes in group
myGap          = 0.2    # relative gap between groups
myBoxWidth     = 0.8    # relative boxwidth within group
myBoxGrid      = (1.0 - myGap)/N
myBoxHalfWidth = myBoxGrid*myBoxWidth/2
myPosY(i)      = column(0) - 0.5 + (i-1)*myBoxGrid + (myBoxGrid + myGap)/2.
myYLow(i)      = myPosY(i) - myBoxHalfWidth
myYHigh(i)     = myPosY(i) + myBoxHalfWidth
myYCenter(i)   = (myYLow(i) + myYHigh(i))/2

set style fill transparent solid 0.5 
set offset 0,0,0.5,0.5
set xrange [600:1100]
set yrange [:] reverse
set ytics out

plot i=1 $Data u (0):0:(0):2:(myYLow(i)):(myYHigh(i)):ytic(1) w boxxy lc 1 title 'Column2', \
     i=1 ''    u 2:(myYCenter(i)):3 w xerr lc 1 notitle, \
     i=2 ''    u (0):0:(0):4:(myYLow(i)):(myYHigh(i)) w boxxy lc 2 title 'Column4', \
     i=2 ''    u 4:(myYCenter(i)):5 w xerr lc 2 notitle
### end of code

Result:

enter image description here