2015-02-11 71 views
3

我有以下示例:曲線用於使用中的R的函數擬合GGPLOT2

seed(123) 
x<-runif(100) 
y<-runif(100) 

f <- function(x) { return(4 * x * (1 - x)) } 

我想顯示與該功能fxy數據點的假想依賴性,示於下面的圖片。

enter image description here

可以用GGPLOT2誰能幫助?

謝謝。

回答

1

使用stat_function()

df <- data.frame(x= runif(100), y = runif(100)) 
f <- function(x) { return(4 * x * (1 - x)) } 

ggplot(aes(x,y), data = df) + geom_point() + 
stat_function(fun=f)