How to Label Distributions in ggplot

Asked

Viewed 1,707 times

6

I have the following graph of the exponential distribution, I want to put a caption showing which parameter of my exponential.

ggplot(data.frame(x=c(0,5)),aes(x))+
  stat_function(fun=dexp,colour='red',size=1.4)+
  stat_function(fun=dexp,args=list(rate=.5),colour='deepskyblue1',size=1.4)+
  stat_function(fun=dexp,args=list(rate=.75),colour='goldenrod2',size=1.4)

inserir a descrição da imagem aqui

1 answer

5

You have to put the colors as an aesthetic (within the aes). And if you want to use these specific colors ('red', 'deepskyblue1', 'goldenrod2'), they have to be passed as parameters in the scale_color_manual:

ggplot(data.frame(x=c(0,5)),aes(x))+ 
  stat_function(fun=dexp, aes(colour='1'),size=1.4)+ 
  stat_function(fun=dexp,args=list(rate=.5), aes(colour='0.5'),size=1.4)+ 
  stat_function(fun=dexp,args=list(rate=.75), aes(colour='0.75'),size=1.4) +
  scale_color_manual("Rate",values = c('red', 'deepskyblue1', 'goldenrod2'))

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.