3

I have to convert the following JPEG image into a TeX-equivilant diagram using tikz and pgfplots.

JPEG image that I want to integrate into my tex document

This is what I have sofar:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
    \begin{document}
        \begin{tikzpicture}
            \begin{axis}[
                width=\linewidth,
                height=8cm,
                ymin=0,
                ytick={0,10,20,30,40,50,60,70,80,90,100},
                ymax=100,
                ylabel={Percentage},
                symbolic x coords={0-15,15-59,60-64,65-69,70-74,75-79,80-84,85-89,90+},
                xtick=data,
                nodes near coords align={vertical}
                ]
                \addplot[draw={rgb:red,36;green,105;blue,179},ultra thick, smooth, nodes near coords] 
                    coordinates {(0-15,0.7) (15-59,0.6) (60-64,1.9) (65-69,3.0) (70-74,5.0) (75-79,9.8) (80-84,21.0) (85-89,38.2) (90+,64.4)};
            \end{axis}
        \end{tikzpicture}
    \end{document}

and this is what it looks like:

enter image description here

The graph almost resembles the aforementioned JPEG image. However I am having problems with the following:

A. How do I draw vertical lines between the bins as seen in the first JPEG Image?

B. How do I remove the x and y axes ticks as seen in my TeX Graph?

C. How do I visualize the big blue dots at the numbered value as seen in the first JPEG Image?

D. How do I shift the visualized numbers at the coords slightly upwards so that they do not interfere with the drawn line?

Any help would be greatly appreciated...

4

B. Use option tick style={draw=none}.

A. For the gray lines use a grid at minor ticks:

minor x tick num=1,
minor ytick={10,30,90},
grid=minor,

C. Use option mark* for the plot and change draw to color.

\addplot[color={rgb:red,36;green,105;blue,179},mark=*,...] ...

D. Use option nodes near coords style to shift the numbers and change the color back to black:

nodes near coords style={yshift=1em,black},

Additionally I would use a smaller font size.

enter image description here

Code:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      width=\linewidth,
      height=8cm,
      ymin=0,
      ytick={0,10,20,30,40,50,60,70,80,90,100},
      ymax=100,
      ylabel={Percentage},
      symbolic x coords={0-15,15-59,60-64,65-69,70-74,75-79,80-84,85-89,90+},
      xtick=data,
      font=\footnotesize,
      tick style={draw=none},
      minor x tick num=1,
      minor ytick={10,30,90},
      grid=minor,
      nodes near coords style={yshift=1em,black},
      ]
      \addplot[color={rgb:red,36;green,105;blue,179},mark=*,ultra thick, smooth, nodes near coords] 
        coordinates {(0-15,0.7) (15-59,0.6) (60-64,1.9) (65-69,3.0) (70-74,5.0) (75-79,9.8) (80-84,21.0) (85-89,38.2) (90+,64.4)};
    \end{axis}
  \end{tikzpicture}
\end{document}
  • 1
    for B draw=none is better – percusse Nov 8 '16 at 18:10
  • @percusse Ok, I have changed this. – esdd Nov 8 '16 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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