2017-02-18 97 views
0

我想在同一個圖上繪製多個正態分佈。下面的代碼可以工作,但是如何在圖中添加顯示相應均值和標準差的圖例。R:ggplot手動添加圖例

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') 

回答

0

你可以嘗試:

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

+0

謝謝!有效 –