title: Plot Student’s t distribution with degrees of freedom
body: <p>I want to plot Student’s t distribution with degrees of freedom 1, 2, 5 and 10; all in one plot and use different colors for each distribution in the plot. Also, create a legend in the top left corner of the canvas and also, increase the line width of the curve for df = 1. </p>
  
  <p>I can do this like this but I'm not sure if there is a better and quicker way to do this:</p>
  
  <pre><code>x &lt;- seq(-3, 3, length=1000)
  hx &lt;- dnorm(x)
  
  degf &lt;- c(1, 2, 5, 10)
  colors &lt;- c("red", "blue", "darkgreen", "gold", "black")
  labels &lt;- c("df=1", "df=2", "df=5", "df=10", "normal")
  
  plot(x, hx, type="l", lty=1, xlab="x value",
       ylab="Density", main="Comparison of t Distributions")
  
  for (i in 1:4){
  
    if (i == 1) {
      lines(x, dt(x,degf[i]), lwd=3, col=colors[i])
    } 
    else
    {
      lines(x, dt(x,degf[i]), lwd=1, col=colors[i])
    }
  }
  
  legend("topleft", inset=.05, title="Distributions",
         labels, lwd=1, lty=c(1, 1, 1, 1, 1), col=colors)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/gfEXA.png" alt="enter image description here"></p>