1
lab <- data.frame(Month = c("2016-01-01", "2016-02-01", "2016-03-01", "2016-04-01", "2016-05-01", "2016-06-01"), AccNumber = c(5683,5418,6001,6184,6001,6184), OCTAT = c(40.20,50.52,47.15,45.03,47.15,45.03), Default = c(30,30,30,30,30,30))
id <- rownames(lab)
lab <- cbind(id = id, lab)
max <- max(lab$AccNumber)
max2 <- max(lab$OCTAT)
p <- barplot(lab$AccNumber, names.arg = lab$Month, xlab = "Month", col = "blue" ,ylim = c(0, max + 2000))
par(new=TRUE)
plot(x = id, y = lab$OCTAT, type = "l", col = "red", axes = FALSE, ylim = c(0, 60), ann = FALSE)
plot(x = id, y = lab$OCTAT, type = "l", col = "green", axes = FALSE, ylim = c(0, 60), ann = FALSE, lwd = 2)
p <- barplot(lab$AccNumber, names.arg = lab$Month, xlab = "Month", col = "blue" ,ylim = c(0, max + 2000))
par(new=TRUE)
plot(x = id, y = lab$OCTAT, type = "l", col = "green", axes = FALSE, ylim = c(0, 60), ann = FALSE, lwd = 2)
axis(4, at=seq(0, max2 + 10, 10))
abline(h = 30, lwd = 2) # Default blue line (30)
abline(lm(lab$OCTAT ~ lab$id), col = "red", lty = 2) #Regression line trend
運行代碼後,這是我下面得到的。我對R完全陌生。我怎樣才能得到一張看起來像第二張照片的迴歸線。regresio行顯示不正確