title: Histogram legend in R
body: <p>I have a histogram of the form</p>
  
  <pre><code>rm(list = ls())
  set.seed(1)
  x1 &lt;- rnorm(100, mean=1)
  x2 &lt;- rnorm(100)
  hist(x1, col="black", ylim=c(0,30), xlim=range(pretty(range(x1, x2))), xlab="x-axis label", ylab="y-axis label", main="", cex.lab=1.3, las=1)
  hist(x2, xlab="", ylab="", main="", ylim=c(0,yhigh), xlim=c(0,.05), density = 20, col= "gray", axes=F, add=TRUE, lty=1)
  lines(density(x2, from = 0, to = max(x2)), col ="firebrick", lwd = 1.5)
  legend("topright", c("group1", "group2", "density"), lty=c(1,1, 1), bty = "n")
  </code></pre>
  
  <p>I am having trouble getting the legend to appear correctly, with a solid black bar, a hatched bar, and a red line to match the data (I know the density line is not right, but including so as to have a line in this example). Anybody know how to do this?  </p>