0

I am trying to add a legend to the qplot generated by this code:

qplot(pa1, geom = "density", fill = I("blue"), alpha = I(0.3), label = "auto") + geom_density(aes(x = pb1), fill = "red", alpha = I(0.3), label = "brand") + 
  geom_density(aes(x = ph1), fill = "green", alpha = I(0.3)) + xlab("Predicted Values") + 
  ylab("Density") + ggtitle("Auto (blue) Brand (red) and Home (green)")

where pa1, pb1, ph1 are vectors of predictions from glm models.

The final output works: enter image description here

but no legend...

Moderat
  • 1,462
  • 4
  • 17
  • 21
  • It would be nice if you actually posted a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) what we could run and edit for you. But the basic idea is that if you want something to show up in the legend, it should be in an `aes()` – MrFlick Oct 21 '14 at 18:49

1 Answers1

0

You might find it more simple to do this way, and the legend is there.

ggplot(diamonds) + geom_density(aes(x=price, colour=clarity,fill=clarity,alpha=.3))
keegan
  • 2,892
  • 1
  • 17
  • 20