[英]Curve fitting for a function in R using ggplot2
我有以下示例:
seed(123)
x<-runif(100)
y<-runif(100)
f <- function(x) { return(4 * x * (1 - x)) }
我想用函數f
和x
和y
的數據點來表示假設的依賴關系,如下圖所示。
任何人都可以幫助使用ggplot2嗎?
謝謝。
使用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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.