-2

how to add legend with ggplot2,every color represent a kind of distrbution ,data Nor_1 can download at http://pan.baidu.com/s/1dDCiTNj ,my code is as follows:

set.seed(100)
ggplot()+geom_density(aes(x=Nor_1),fill="red",color="black",size=1,alpha=0.3,adjust=1)+geom_density(aes(x=rpois(100,2)),fill=rgb(0.1,0.9,0.8),color="black",alpha=0.3,adjust=1)+geom_density(aes(x=rnbinom(100,size=0.2,mu=4)),fill="yellow",color="black",size=1,alpha=0.3,adjust=2)+geom_smooth()+coord_cartesian(xlim=c(-10,20))

enter image description here

user4672728
  • 96
  • 1
  • 9

1 Answers1

0

You can add X,Y labels, title etc. using labs() function:

    dat = data.frame(a= rnorm(n = 1000,mean = 100, sd = 10), b= rnorm(n = 1000,mean = 50, sd = 10));
ggplot(dat) + geom_density(aes(a),fill="red",color="black",size=1,alpha=0.3) + 
              geom_density(aes(b),fill="blue",color="black",size=1,alpha=0.3) +
              labs(x="your X lab", y= "your Y lab", title="your title")
vibi
  • 13
  • 5