資料數不多,直接看整筆資料
## College SAT_No GPA_No SAT_Yes GPA_Yes
## 1 Barnard 1210 3.08 1317 3.30
## 2 Northwestern 1243 3.10 1333 3.24
## 3 Bowdoin 1200 2.85 1312 3.12
## 4 Colby 1220 2.90 1280 3.04
## 5 Carnegie Mellon 1237 2.70 1308 2.94
## 6 Georgia Tech 1233 2.62 1287 2.80
繪圖
# 畫框,定義數值
plot.new()
par(mar=c(1,5,1,5))
par(oma=c(4,3,1,3))
plot(dta$SAT, dta$GPA, type = "n", xlim = c(1150, 1400),
ylim = c(2.6, 3.4), xlab = "SAT", ylab = "GPA")
# 畫點、線
points(dta$SAT_No, dta$GPA_No, pch = 19, cex = 2)
points(dta$SAT_Yes, dta$GPA_Yes, pch = 1, cex = 2)
legend("topleft", legend=c("Submitted SAT Scores", "Did NOT Submit SAT Scores"), pch = c(1, 19), bty = "n", cex = c(1,1))
# 標註名稱
text(x=c(1340, 1365, 1335, 1301, 1345, 1319), y=c(3.30, 3.24, 3.12, 3.04, 2.94, 2.80), labels=c("Barnard", "Northwestern", "Bowdoin", "Colby", "Carnegie Mellon", "Georgia Tech"), cex=.7)
# 畫點與點之間的線(Bowdoin加粗)
with(dta, segments(SAT_No, GPA_No, SAT_Yes, GPA_Yes, lty=1, lwd=1, col="black"))
segments(1200, 2.85, 1312, 3.12, lty=1, lwd=2)