0

I am trying to plot multiple Normal distribution on same graph. The code below works but how do I add legend showing the corresponding mean and standard deviation in the graph.

ggplot(data.frame(x = c(-4, 4)), aes(x)) + 
stat_function(fun = dnorm, args = list(mean = 0, sd = 1), col='red') +
stat_function(fun = dnorm, args = list(mean = 0, sd = .5), col='blue')
Cœur
  • 37,241
  • 25
  • 195
  • 267
chintan s
  • 6,170
  • 16
  • 53
  • 86

1 Answers1

1

You could try:

ggplot(data.frame(x = c(-4, 4)), aes(x)) + 
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1), aes(colour = "mean = 0 / sd =1")) +
  stat_function(fun = dnorm, args = list(mean = 0, sd = .5),aes(colour = "mean = 0 / sd =0.5"))+
  scale_colour_manual("Parameters",values=c("blue","red"))

enter image description here

Haboryme
  • 4,611
  • 2
  • 18
  • 21