【发布时间】:2019-01-19 02:37:15
【问题描述】:
我正在尝试在名为“final”的数据框中的两列数据之间绘制图表。我希望 p 值和 r^2 值显示在图表上。
我正在使用这个函数和代码,但它给了我错误“找不到 y 值”
library(ggplot2)
lm_eqn <- function(final, x, y){
m <- lm(final[,y] ~ final[,x])
output <- paste("r.squared = ", round(summary(m)$adj.r.squared, digits = 4), " | p.value = ", formatC(summary(m)$coefficients[8], format = "e", digits = 4))
return(output)
}
output_plot <- lm_eqn(final, x, y)
p1 <- ggplot(final, aes(x=ENSG00000153563, y= ENSG00000163599)) + geom_point() + geom_smooth(method=lm, se=FALSE) + labs(x = "CD8A", y = "CTLA-4") + ggtitle("CD8 v/s CTLA-4", subtitle = paste("Linear Regression of Expression |", output_plot))
如何让数据 x 和 y 的两列都流过函数,并让图表在图表上打印 p 值和残差值?
提前致谢。
【问题讨论】:
-
请see here 提出人们可以帮助解决的 R 问题,包括您的数据的代表性样本
标签: r function variables ggplot2