Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to draw a chart with "The Economist" style. With tikz, I draw this chart clumsily, so I would like to know is that possible to draw this chart elegantly with pgfplots.

    \begin{tikzpicture}[ybar]
        \draw[red,thin] (0,0) -- (3.6,0) node [right,color=black,font=\footnotesize] {0};
        \draw[white,thin] (0,0.5) -- (3.6,0.5) node [right,color=black,font=\footnotesize] {10};
        \draw[white,thin] (0,1) -- (3.6,1) node [right,color=black,font=\footnotesize] {20};
        \draw[white,thin] (0,1.5) -- (3.6,1.5) node [right,color=black,font=\footnotesize] {30};
        \draw[white,thin] (0,2) -- (3.6,2) node [right,color=black,font=\footnotesize] {40};
        \draw[white,thin] (0,2.5) -- (3.6,2.5) node [right,color=black,font=\footnotesize] {50};
        \draw[white,thin] (0,3) -- (3.6,3) node [right,color=black,font=\footnotesize] {60};
        \draw[color=blue,fill=blue!40!black,bar width=8pt] 
            plot coordinates {(1.2,0.85)} node [above,color=black,font=\tiny] {WWI};
        \draw[color=blue,fill=blue!60,bar width=8pt] 
            plot coordinates {(2.4,2.5)} node [above,color=black,font=\tiny] {Spanish Flu};
        \draw[color=red,fill=red] (-0.3,4) rectangle (-0.5,4.5);
        \node[below right] at (-0.3,4.5) {
            \begin{tabular}{l}
                \footnotesize\textbf{Mortality}\\
                \tiny{million}\\                    
            \end{tabular}
            };
        \begin{pgfonlayer}{background}
            \fill[blue!90!black!25] (-0.5,4.5) rectangle (4.5,-0.4);
        \end{pgfonlayer}
    \end{tikzpicture}

There are some questions:

  1. How to hide y axis but remain the ytick and y major grid?
  2. Can I set the separation space between ticks?
  3. How to add a red rectangle in the title and move it to the upper left corner?

Thank you for your kindly help!

share|improve this question
2  
Could you edit your code to turn it into a compilable document? –  Alan Munn Jul 6 '11 at 2:57
add comment

1 Answer 1

  1. To only hide the y axis line but keep the ticks and the grid, you can use y axis line style={opacity=0} to make the line transparent (draw=none doesn't seem to work here).

  2. To specify the interval between the ticks, it is usually easiest to set them using something like ytick={0,10,...,100}.

  3. The rectangle can be added using extra description/.code={...}. The standard coordinate system for TikZ commands in this context is the axis description cs, where (0,0) is the lower left corner of the plot area, and (1,1) is the upper right. You can use values <0 and >1. In this case, I would also typeset the title as an extra description, because it's easier to get the positioning right. To make the rectangle appear snug in the corner, you should set tight background rectangle for the background, otherwise TikZ will add some padding.

Here's an example where I defined a new economist style for an axis environment. The style takes an optional argument to define the title.

As maetra points out, the style seems to have changed at some point in 2012. I have included a second style, economist new that uses a white background and a frame around the labels.

PGFplots chart in The Economist Style

PGFPlots chart in new The Economist Style

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{pgfplots}

\begin{document}

\definecolor{backgroundcolor}{RGB}{213,228,235}
\definecolor{plotcolor1}{RGB}{1,77,100}
\definecolor{plotcolor2}{RGB}{1,162,217}

\pgfplotscreateplotcyclelist{economist}{%
    fill=plotcolor1,draw=plotcolor1,text=black\\%
    fill=plotcolor2,draw=plotcolor2,text=black\\%
}

\pgfplotsset{
    economist/.style={
        ybar,
        ymin=0,
        enlarge x limits=1.5,
        nodes near coords,
        every axis plot post/.append style={
            point meta=explicit symbolic
        },
        /tikz/background rectangle/.style={
            fill=backgroundcolor
        },
        tight background,
        show background rectangle,
        cycle list name=economist,
        axis x line*=bottom,
        x axis line style={black},
        xtick=\empty,
        axis y line=right,
        y axis line style={opacity=0},
        ytick={0,10,...,100},
        tickwidth=0pt,
        grid=major,
        grid style=white,
        extra description/.code={
            \fill [red] (-0.05,1.15) rectangle +(-1em,6ex);
            \node [anchor=base west, inner sep=0pt] at (0,1.15) {\large\textbf{#1}};
            \node [anchor=base west, inner sep=0pt] at (0,1.075) {\small Million};
        },
    },
    economist/.default={},
    economist new/.style={
        economist=#1,
        /tikz/background rectangle/.style={
            fill=white
        },
        grid style=gray!50,
        every node near coord/.append style={
            draw=cyan!50!blue,
            fill=white,
            inner sep=2pt,
            outer sep=3pt
        }
    },
    economist new/.default={},
}

\begin{tikzpicture}
\begin{axis}[economist new=Mortality, ymax=60]
\addplot coordinates {(1,18) [WW1]};
\addplot coordinates {(2,50) [Spanish Flu]};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Exactly Jake, my text live version in ubuntu 11.10 was an old one (2009). Now installed Tex Live 2011 and it works! –  user13167 Apr 1 '12 at 12:03
    
Looks great. Is there a way to draw the plots behind the grind? –  schmendrich Apr 1 '12 at 12:29
    
@schmendrich: Thanks! You can just set axis on top to draw the grid lines on top of the plot. –  Jake Apr 1 '12 at 12:32
    
Just that easy... thank you. –  schmendrich Apr 1 '12 at 18:01
    
@Jake, it seems as if the Economist has a different style now, as least on its website: The background is white while the lines are grey. Also if the line crosses the coordinate information like WW1, there is a box around the label. –  maetra Jan 11 '13 at 10:20
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.