gpt4 book ai didi

r - 使用 ggplot2 对 R 中的函数进行曲线拟合

转载 作者:行者123 更新时间:2023-12-04 19:57:09 25 4
gpt4 key购买 nike

我有以下示例:

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

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

我想用函数 f 显示一个假设的依赖关系和 x 的数据点和 y如下图所示。

enter image description here

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

关于r - 使用 ggplot2 对 R 中的函数进行曲线拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28458381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com