1

I use following script (see also here) below, to draw this figure:

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    width=14cm,
    height=7cm,
    enlargelimits=false,
    axis x line=bottom,
    axis y line=right,
    axis line style={-},
    tickwidth=2pt,
    domain=-3:3,
    xtick={-3,-2,-1,0,1},
    xticklabels={
      Innovators 2.5\%,
      Early Adopters 13.5\%,
      Early Majority 34\%,
      Late Majority 34\%,
      Laggards 16\%,
    },
    x tick label style={rotate=45,anchor=east},
    ylabel={Market share \%},
    ytick={0,25,50,75,100},
    ymin=0, ymax=110,
    samples=51, smooth, no markers,
    ]

    \addplot+[blue,very thick] {50*exp(-.5*x^2)};

    \addplot+[red,very thick] {100 / (1 + exp(-2*x))};

    \pgfplotsinvokeforeach{-3,...,1} {
      \draw[help lines] (axis cs:#1,{50*exp(-.5*(#1)^2)}) -- (axis cs:#1,0);
    }

  \end{axis}
\end{tikzpicture}
\end{document}

I tried to put a line-break to the x-axis descriptions:

xticklabels={
      Innovators \\ 2.5\%,
      Early Adopters \\ 13.5\%,
      Early Majority \\ 34\%,
      Late Majority \\ 34\%,
      Laggards \\ 16\%,
    },

However, this didn't change the plot. Secondly, I also like to add a semi-transparent box with a description behind the graph.

enter image description here

Questions:

  1. How can I add a line break, so that the percentage numbers are in a new line?
  2. How can I add a description box, as described?

Thanks for your help!

2

Define text width for the xtick label to solve the first problem.

x tick label style={rotate=45,anchor=east,text width=3cm,align=right},

The fill command along with a node to put text can solve the second issue. something like this:

\fill[gray,opacity=0.5] (axis cs:0,0) rectangle (axis cs:1,100);
\node[above] at (axis cs:0.5,100){some text};

enter image description here

The complete code:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    width=14cm,
    height=7cm,
    enlargelimits=false,
    axis x line=bottom,
    axis y line=right,
    axis line style={-},
    tickwidth=2pt,
    domain=-3:3,
    xtick={-3,-2,-1,0,1},
    xticklabels={
      Innovators\\2.5\%,
      Early Adopters\\ 13.5\%,
      Early Majority\\ 34\%,
      Late Majority\\ 34\%,
      Laggards\\ 16\%,
    },
    x tick label style={rotate=45,anchor=east,text width=3cm,align=right},
    ylabel={Market share \%},
    ytick={0,25,50,75,100},
    ymin=0, ymax=110,
    samples=51, smooth, no markers,
    ]

    \addplot+[blue,very thick] {50*exp(-.5*x^2)};

    \addplot+[red,very thick] {100 / (1 + exp(-2*x))};
    \fill[gray,opacity=0.5] (axis cs:0,0) rectangle (axis cs:1,100);
     \node[above] at (axis cs:0.5,100){some text};
    \pgfplotsinvokeforeach{-3,...,1} {
      \draw[help lines] (axis cs:#1,{50*exp(-.5*(#1)^2)}) -- (axis cs:#1,0);
    }


  \end{axis}
\end{tikzpicture}
\end{document}

EDIT

Another way to solve first issue is to set minimum size. Since OP wants the text to be aligned in center, align=center is used.

x tick label style={rotate=45,anchor= north east,minimum size = 1cm,align=center},

The output corresponding to this line:

enter image description here

  • Is there maybe a better solution to x tick label style={rotate=45,anchor=east,text width=3cm,align=right},? Because I like to align both elements centrally – Christopher Dec 13 '18 at 17:20
  • @Christopher both elements means? first and second line in x tick label ? – nidhin Dec 13 '18 at 17:27
  • Yes, exact. The current version seems to align is right? – Christopher Dec 14 '18 at 7:49
  • 1
    @Christopher x tick label style={rotate=45,anchor=east,text width=3cm,align=center}, can do that. You can try x tick label style={rotate=45,anchor=east,minimum size=1cm,align=center}, also. – nidhin Dec 14 '18 at 9:06
  • 1
    @Christopher see updated answer also. – nidhin Dec 14 '18 at 9:42

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.