我正试图在R中的回归图上绘制r2和p值,借助于
this page
. 这是我的密码。
DF <- data.frame(X <- c(1, 2, 3, 4, 5, 6, 7), Y <- c(1.5, 2.1, 1.2, 4.4, 1, 6.5, 8.4))
plot(Y ~ X, data = DF)
# Add regression line
regline <- lm(DF$Y ~ DF$X)
intercept <- coef(regline)[1]
slope <- coef(regline)[2]
abline(regline)
# Get stats
summary(regline)
# Get these values
names(summary(regline))
# Get adjusted R-square
R2 <- summary(regline)$adj.r.squared
# Get pPvalue
P <- summary(regline)$coefficients[2,4]
P <- ifelse(P < 0.05, '< 0.05', P)
# Plot R2 and P-value
r2p = vector('expression', 2)
r2p[1] = substitute(expression(italic(R)^2 == RSQ), list(RSQ = format(R2, dig = 2)))[2]
r2p[2] = substitute(expression(italic(P) == PVALUE), list(PVALUE = format(P, digits = 2)))[2]
legend('topleft', legend = r2p, bty = 'n', y.intersp = 1.3)
我想做的不同是,如果p值小于0.05,将p值更改为“p<0.05”。我可以转换该值,但它仍然像这样输出“=”符号。
如何在保持斜体P的同时打印“P<0.05”而不是“P=<0.05”?谢谢你的帮助。