我试图在R中的回归图上绘制R2和P-值,并得到此页的帮助。这是我的密码。
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”?谢谢你的帮助。
发布于 2019-01-18 22:00:11
将r2p[2]
中的表达式修改为下列形式之一:
expression(italic(P) ~ PVALUE)
expression(italic(P) * PVALUE)
expression(paste(italic(P), PVALUE))
也就是说,将上面的任何代码放入place xxxxxx
中
r2p[2] = substitute(xxxxxx, list(PVALUE = format(P, digits = 2)))[2]
有关详细信息,请查看?plotmath
和demo(plotmath)
。
https://stackoverflow.com/questions/54261740
复制相似问题