0

I want to connect the bars of each series of my multiple series bar chart with a line going from node to node.

enter image description here

Thus, all blue bar connected with a blue line and all orange bars with a orange line. However, I don't manage to do this. Is there a way to set the plot type from ybar to line?

The solution in a previous question on this topic does not seem to work as I work with multiple series.

\begin{figure}[!!h]
    \centering
    \pgfplotstableread{
1   1.64     6.27
2   5.67    -27.13
3   3.58    -9.36
4   6.25    -10.74

    }\dataset
  \begin{tikzpicture}
  \centering
\begin{axis}[ybar,
     ymin=-32,
    ymax=25,   
    xmin=0.6,
    xmax=4.4,  
    ylabel={Return in \% },
    bar width=20pt,
    xtick=data,
    enlargelimits=true,
    xticklabels ={Pre(0),Pre(1),Crisis(2),Post(3)},
    nodes near coords,
    major x tick style = {opacity=0},
    xticklabel style=
{rotate=45,anchor=near xticklabel},
        minor x tick num = 1,
        minor tick length=2ex,
        ]
        \addplot[draw=blue,fill=blue!20] table[x index=0,y index=1] \dataset; %Data1
        \addplot[draw=orange,fill=orange!40] table[x index=0,y index=2] \dataset; %Data2

    \legend{First Day MAR, 36 months BHAR};
    \end{axis}


\end{tikzpicture}
 \caption{Averages per issue period}
 \end{figure}

1 Answer 1

2

The best solution I can think of for now is to duplicate the plots, but without the option fill and then add smooth (or sharp) to use a line.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.13}

\pgfplotstableread{
1   1.64     6.27
2   5.67    -27.13
3   3.58    -9.36
4   6.25    -10.74
}\dataset

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=-32,
    ymax=25,   
    xmin=0.6,
    xmax=4.4,  
    ylabel={Return in \% },
    bar width=20pt,
    xtick=data,
    enlargelimits=true,
    xticklabels ={Pre(0),Pre(1),Crisis(2),Post(3)},
    nodes near coords,
    major x tick style = {opacity=0},
    xticklabel style=
{rotate=45,anchor=near xticklabel},
        minor x tick num = 1,
        minor tick length=2ex,
]

\addplot[draw=blue,fill=blue!20] table[x index=0,y index=1] \dataset; %Data1
\addplot[draw=orange,fill=orange!40] table[x index=0,y index=2] \dataset; %Data2

\addplot[smooth, draw=blue] table[x index=0,y index=1] \dataset; %Data1
\addplot[smooth, draw=orange] table[x index=0,y index=2] \dataset; %Data2

\legend{First Day MAR, 36 months BHAR};
\end{axis}
\end{tikzpicture}
\end{document}
2
  • Thank you, in combination with the tension key this is exactly what I needed!
    – TDeg
    Aug 29, 2016 at 18:43
  • @TDeg if it solved your question, please consider marking it as such. :)
    – Alenanno
    Aug 29, 2016 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .