I used \includegraphics[height=1.91in,width=5in]{L1F2.jpg} to insert an image in the document. B
ut I would like to draw similar picture in latex and add my own text on it similar to what is included and change the arrows a little. What is the best way to do so?
Asked
Active
Viewed 1,452 times
0
Torbjørn T.
- 206,688
Falcon-StatGuy
- 171
2 Answers
1
I'd use PSTricks. Here is a sample code:
\documentclass[12pt]{article}
\usepackage{pst-all,pst-infixplot,pst-blur}
\begin{document}
\begin{center}
\begin{pspicture}(-1,-1.5)(3.5,1.5)
\psline{->}(0,0)(0,4)\rput[r](-0.1,3.8){$y$}
\psline{->}(0,0)(4,0)\rput[t](3.8,-0.1){$x$}
\psline[linecolor=orange]{-}(0,1)(4,3)
\psset{plotpoints=1000}
\infixtoRPN{0.4*2.7^(-10*x*x)}
\psline(1,0.5)(1,2.5)
\rput[l]{-90}(1,1.5){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
\pnode(1,1.5){k1}
\psline(2,1)(2,3)
\rput[l]{-90}(2,2){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
\pnode(2,2){k2}
\psline(3,1.5)(3,3.5)
\rput[l]{-90}(3,2.5){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
\pnode(3,2.5){k3}
\pnode(3.2,2.8){p1}
\rput[r]{0}(-0.2,2){\ovalnode[shadow=true,blur=true]{E}{$E[Y_1]=\beta_0+\beta_1\,X_1$}}
\ncarc{->}{E}{k1}
\rput[l]{0}(4,3){\ovalnode[shadow=true,blur=true]{dis}{Distribution of $\epsilon_3$}}
\rput(1,0){$|$}\rput[t](1,-0.1){$x_1$}
\rput(2,0){$|$}\rput[t](2,-0.1){$x_2$}
\rput(3,0){$|$}\rput[t](3,-0.1){$x_3$}
\ncarc{->}{dis}{p1}
\end{pspicture}
\end{center}
\end{document}
\endinput
0
There are several methods/packages for "programming" diagrams with LaTeX. Perhaps the most popular package these days is TikZ. There will also be multiple ways of doing this with TikZ, I present one option below, which produces this:
There are a few comments in the code, but they're by no means very detailed. The manual, which will seem very large and intimidating at first, is a very useful reference. It also starts out with a few tutorials, aimed at introducing new users to making diagrams with TikZ.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
arrows.meta, % supplies the Stealth arrow tip
bending
}
\tikzset{
distribution/.pic={ % define a small "picture" that can be used multiple times
\draw [thick] (0,1) -- (0,-1);
\draw [thin,dotted] (0,0) coordinate (-origin) -- (0.7,0);
\draw [blue] (0.05,1) .. controls (0.08,0.2) and (0.6,0.3) ..
coordinate[pos=0.5] (-left)
(0.6,0) .. controls (0.6,-0.3) and (0.08,-0.2) ..
(0.05,-1)
coordinate[pos=0.5] (-right);
}
}
\begin{document}
\begin{tikzpicture}
% draw the axis with labels
\draw [Stealth-Stealth] (0,4) node[left]{$y$} |- (6,0) node[below] {$x$};
% draw the straight line plot
\draw [orange] plot[domain=0:6,samples=2](\x,1+\x*0.5);
% a loop to add the small distribution graphs and ticklabels on x-axis at three x-values
\foreach [count=\i] \x in {1.5,3,4.5} {
\draw (\x,1+\x*0.5) pic (p\i) {distribution}; % pic{distribution} draws the small picture defined above
\draw (\x,3pt) -- (\x,0) node[below] {$x_\i$}; % draw the tick and ticklabel
}
% draw arrows with annotations
\draw [-Stealth] (p3-right) to[out=-45,in=180] ++(0.8,-0.5) node[right] {Distribution of $\epsilon_3$};
\draw [Stealth-,shorten <=3pt] (p1-origin) -- ++(-1.7,0.2) node[left] {$E(Y_1) = \beta_0 + \beta_1X$};
\end{tikzpicture}
\end{document}
Torbjørn T.
- 206,688



pdflatex. Not everyone is familiar with PSTricks.) – Torbjørn T. Dec 31 '16 at 21:03