相关疑难解决方法(0)

在图上添加回归线方程和R2

我想知道如何添加回归线方程和R ^ 2 ggplot.我的代码是

library(ggplot2)

df <- data.frame(x = c(1:100))
df$y <- 2 + 3 * df$x + rnorm(100, sd = 40)
p <- ggplot(data = df, aes(x = x, y = y)) +
            geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
            geom_point()
p
Run Code Online (Sandbox Code Playgroud)

任何帮助将受到高度赞赏.

r ggplot2 ggpmisc

207
推荐指数
8
解决办法
23万
查看次数

从ggplot2创建的nls拟合中提取系数

有一个很好的解释这里的如何使用GGPLOT2创建散点图,利用NLS拟合数据,并绘制配合,都在一条线,像这样

myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) )

ggplot(data=myhist, aes(x=size, y=counts)) + geom_point() + 
    geom_smooth(method="nls", formula = y ~ N * dnorm(x, m, s), se=F, 
    start=list(m=20, s=5, N=300)) 
Run Code Online (Sandbox Code Playgroud)

我的问题是:使用这种结构,是否有可能从该调用中拉出实际的nls对象?我想知道我的系数等.现在我无法弄清楚如何在不进行单独的nls调用的情况下获取它们.

r nls ggplot2

4
推荐指数
1
解决办法
4414
查看次数

标签 统计

ggplot2 ×2

r ×2

ggpmisc ×1

nls ×1