【发布时间】:2016-09-28 22:47:33
【问题描述】:
我得到了这个情节
使用下面的代码
library(dplyr)
library(ggplot2)
library(ggpmisc)
df <- diamonds %>%
dplyr::filter(cut%in%c("Fair","Ideal")) %>%
dplyr::filter(clarity%in%c("I1" , "SI2" , "SI1" , "VS2" , "VS1", "VVS2")) %>%
dplyr::mutate(new_price = ifelse(cut == "Fair",
price* 0.5,
price * 1.1))
formula <- y ~ x
ggplot(df, aes(x= new_price, y= carat, color = cut)) +
geom_point(alpha = 0.3) +
facet_wrap(~clarity, scales = "free_y") +
geom_smooth(method = "lm", formula = formula, se = F) +
stat_poly_eq(aes(label = paste(..rr.label..)),
label.x.npc = "right", label.y.npc = 0.15,
formula = formula, parse = TRUE, size = 3)
除了 R2,我还想将 p 值添加到构面。我可以通过先运行回归然后获取 p 值并使用 geom_text() 添加这些 p 值 similar to the answer of this question. 来手动执行此操作
有没有更快或自动化的方法来做到这一点?例如类似于添加 R2 值的方式。
更新
我所说的 p 值是 斜率 p 值。当 p 时,趋势被认为具有高度统计显着性。
【问题讨论】:
-
这不是this question 的副本。它基本上告诉你使用
summarize() -
请参阅
ggpmisc包作者的answer 至ggplot2: Adding Regression Line Equation and R2 on graph 了解更多详情或联系作者。 -
你看过
stat_fit_glance吗?来源:cran.r-project.org/web/packages/ggpmisc/vignettes/examples.html -
p 值并不意味着“每个趋势显着不同于零的概率”