我正在尝试将形状添加到回归模型中。这是示例:
library(ggpubr)
data(iris)
iris$ran <- as.factor(rep(c(1:2), each = 75))
fit <- lm(Sepal.Length ~ Petal.Width+Species+ran, data = iris)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1],
color=names(fit$model)[3], shape=names(fit$model)[4])) +
geom_point() +
geom_smooth(aes_string(fill = names(fit$model)[3], color = names(fit$model)[3]),
method = "lm", col= "red", fullrange = TRUE) +
labs(x=expression(paste("Petal Width")),
y=expression(paste("Sepal Length")),
caption = paste("R2 =",signif(summary(fit)$r.squared, 2),
"\tAdj R2 =",signif(summary(fit)$adj.r.squared, 2),
"\tIntercept =",signif(fit$coef[[1]],2 ),
"\tSlope =",signif(fit$coef[[2]], 2),
"\tP =",signif(summary(fit)$coef[2,4], 2)))+
theme_classic2(base_size = 14)
对于每个因素,我得到一个带有四条线性线的图。我宁愿只希望“物种”的线性回归线,但“跑”的不同形状(不向图中添加“跑”的回归线)。
此外,我还打算将“R2”更改为 R^2,这是我无法使用当前脚本执行的操作,并将运行的图例更改为“随机”-“Factor1”和“Factor2”。
预先感谢您的帮助。