簡體   English   中英

使用ggplot2曲線擬合R中的函數

[英]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)) }

我想用函數fxy的數據點來表示假設的依賴關系,如下圖所示。

在此輸入圖像描述

任何人都可以幫助使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM