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:
- How to hide y axis but remain the ytick and y major grid?
- Can I set the separation space between ticks?
- How to add a red rectangle in the title and move it to the upper left corner?
Thank you for your kindly help!
Best Answer
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).To specify the interval between the ticks, it is usually easiest to set them using something like
ytick={0,10,...,100}
.The rectangle can be added using
extra description/.code={...}
. The standard coordinate system for TikZ commands in this context is theaxis 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 anextra description
, because it's easier to get the positioning right. To make the rectangle appear snug in the corner, you should settight 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.