2015-02-11 69 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)