【问题标题】:Does ggpmisc::stat_poly_eq recompute the trend line math to get the labels?ggpmisc::stat_poly_eq 是否重新计算趋势线数学以获取标签?
【发布时间】:2021-08-20 05:14:17
【问题描述】:
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,它会重新计算第二次以获得标签吗?

【问题讨论】:

    标签: r ggplot2 ggpmisc


    【解决方案1】:

    是的,它们会适合它两次。我不知道有一种方法可以在“ggplot2”中避免这种情况而不依赖于编写一对新的 stat + geom。我认为这是可以做到的,而且实际上是对软件包的一个很好的增强。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 2021-07-25
      • 2020-01-16
      • 2012-03-07
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      相关资源
      最近更新 更多