我正在尝试为此代码生成的qplot
添加图例:
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)")
其中pa1, pb1, ph1
是来自glm
模型的预测向量。
最终输出有效:
但没有传说......
答案 0 :(得分:0)
你可能会发现这样做更简单,传说就在那里。
ggplot(diamonds) + geom_density(aes(x=price, colour=clarity,fill=clarity,alpha=.3))