1
ggplotRegression <- function (fit) {
require(ggplot2)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y =
names(fit$model)[1])) +
geom_point() +
stat_smooth(method = "lm", col = "red") +
labs(title = paste("Adj R2 = ",signif(summary(fit)$adj.r.squared,
5),
"Intercept =",signif(fit$coef[[1]],5),
" Slope =",signif(fit$coef[[2]], 5),
" P =",signif(summary(fit)$coef[2,4], 5)))
}如何在ggplot2的同一個圖中添加不同分位數的不同圖例?
taus <-c(0.05 , 0.25, 0.50 , 0.75, 0.90 , 0.95)
m <- ggplotRegression(lm(formula = BMI ~ height_in_m
+weight_in_kg+ Highest_Education_level +
wealth_index + age_in_year_groups, data = dat_new))
m+geom_quantile(quantiles=taus, lwd=1.5 , col="green4",
fill=taus)
現在我想添加特定的顏色爲每個分位數並添加spcific傳說每個位數。