R 具有输出的每个方面的系数。type=";“数字”;在ggpmisc::stat\u poly\u eq中
R 具有输出的每个方面的系数。type=";“数字”;在ggpmisc::stat\u poly\u eq中,r,ggplot2,ggpmisc,R,Ggplot2,Ggpmisc,ggpmisc::stat\u poly\u eq有一个选项output.type=“numeric”,可以获得拟合模型的参数估计值。下面是我尝试将其与facet\u wrap一起使用的内容。我在每个方面得到不同的R²,但在这两个方面的系数是相同的。我是做错了什么,还是一个bug library(ggpmisc) set.seed(4321) x <- 1:100 y <- (x + x^2 + x^3) + rnorm(length(x), mean = 0, sd = mean
ggpmisc::stat\u poly\u eq
有一个选项output.type=“numeric”
,可以获得拟合模型的参数估计值。下面是我尝试将其与facet\u wrap
一起使用的内容。我在每个方面得到不同的R²
,但在这两个方面的系数是相同的。我是做错了什么,还是一个bug
library(ggpmisc)
set.seed(4321)
x <- 1:100
y <- (x + x^2 + x^3) + rnorm(length(x), mean = 0, sd = mean(x^3) / 4)
my.data <- data.frame(x = x,
y = y,
group = c("A", "B"))
my.data[my.data$group=="A",]$y <- my.data[my.data$group=="A",]$y + 200000
formula <- y ~ poly(x, 1, raw = TRUE)
myformat <- "Intercept: %s\nSlope: %s\nR²: %s"
ggplot(my.data, aes(x, y)) +
facet_wrap(~ group) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
stat_poly_eq(formula = formula, output.type = "numeric",
mapping = aes(label =
sprintf(myformat,
formatC(stat(coef.ls)[[1]][[1, "Estimate"]]),
formatC(stat(coef.ls)[[1]][[2, "Estimate"]]),
formatC(stat(r.squared)))))
库(ggpmisc)
种子集(4321)
好的,我知道了
ggplot(my.data, aes(x, y)) +
facet_wrap(~ group) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
stat_poly_eq(
formula = formula, output.type = "numeric",
mapping = aes(label =
sprintf(myformat,
c(formatC(stat(coef.ls)[[1]][[1, "Estimate"]]),
formatC(stat(coef.ls)[[2]][[1, "Estimate"]])),
c(formatC(stat(coef.ls)[[1]][[2, "Estimate"]]),
formatC(stat(coef.ls)[[2]][[2, "Estimate"]])),
formatC(stat(r.squared)))))
0.3.2版的“ggpmisc”现在在CRAN中。本周早些时候提交。在文档中,我现在给出了一些使用包“gginnards”中的geom_debug()。例如,它的工作原理如下:
库(ggpmisc)
图书馆(内部)
种子集(4321)
是的,我试过geom=“debug”
。但是我们在打印输出中看不到coef.ls
列表的内容。如果我们能存储这些打印输出,那就太好了。是的,这是有可能的,只需要一点技巧。请看上面对我先前答案的补充。谢谢你的报道。我确实需要扩展“gginnards”的文档。
ggplot(my.data, aes(x, y)) +
facet_wrap(~ group) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
stat_poly_eq(formula = formula, output.type = "numeric",
aes(label = ""),
summary.fun = function(x) {x[["coef.ls"]][[1]]})