library(ggplot2)
library(dplyr)
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"),
facet = c("C", "D", "E", "F", "G"),
y2 = y * c(0.5,2),
w = sqrt(x))
formula <- y ~ poly(x, 3, raw = TRUE)
ggplot(my.data %>% group_by(facet, group) %>% mutate(n = n()), aes(x, y, n = n, color = facet)) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
facet_grid(vars(group)) +
ggpmisc::stat_poly_eq(aes(label = paste(stat(rr.label), paste("N ~`=`~", n), sep = "*\", \"*")),
formula = formula, parse=T)geom_smooth将计算一次数学来绘制趋势线。如果我随后添加ggpmisc::stat_poly_eq,它是否会再次重新计算数学以获得标签?
发布于 2021-06-03 19:54:04
是的,它们会适合它两次。我不知道有什么方法可以在'ggplot2‘中避免这种情况,而不是依赖于编写一对新的stat + geom。我认为这是可以做到的,事实上,这将是对整个包的一个很好的增强。
https://stackoverflow.com/questions/67798441
复制相似问题