Korea a presidential election

silver의 code를 바탕으로 16대 각 지역별 당 지지도를 통한 18대 대통령 예측

ms <- read.csv("C:\\Users\\ms\\Desktop\\ms.csv", header = T)
ms$wrong.saenuri <- ifelse(ms$result.saenuri >= ms$saenuri.min & ms$result.saenuri <= 
    ms$saenuri.max, 0, 1)
ms$wrong.minju <- ifelse(ms$result.minju >= ms$minju.min & ms$result.minju <= 
    ms$minju.max, 0, 1)
par(mar = c(0, 0, 0, 0))
plot(NULL, xlim = c(-30, 100), ylim = c(-1, 20), yaxt = "n", ann = FALSE, xaxt = "n", 
    bty = "n")
text(55, 16, "18대 대선 결과 예측", pos = 3)
for (i in seq(from = 1, to = 16, by = 2)) {
    rect(-26, i - 0.5, 100, i + 0.5, col = "#CEF279", border = NA)
}

for (i in seq(from = 10, to = 90, by = 10)) {
    segments(i, -0.5, i, 15.5, col = "#FFB2F5")
    text(i, 16, paste(i, "%", sep = ""), cex = 0.4, pos = 1)
}
segments(50, -0.5, 50, 15.5, col = "#F361DC")

for (i in seq_along(ms$State)) {
    j <- 16 - i
    segments(ms$saenuri.min[i], j - 0.3, ms$saenuri.max[i], j - 0.3, col = "blue")
    segments(ms$minju.min[i], j - 0.1, ms$minju.max[i], j - 0.1, col = "red")
    text(0, j, ms$State[i], cex = 0.9, pos = 2)
    if (ms$wrong.saenuri[i]) {
        text(2, j, "*", col = "blue", cex = 1, pos = 2)
    }
    if (ms$wrong.minju[i]) {
        text(4, j, "*", col = "red", cex = 1, pos = 2)
    }
    points(ms$result.saenuri[i], j + 0, cex = 0.6, pch = 25, col = "#0000FFAA", 
        bg = "#0000FFAA")
    points(ms$result.minju[i], j + 0.2, cex = 0.6, pch = 25, col = "#FF0000AA", 
        bg = "#FF0000AA")
}

segments(12, -1, 22, -1, col = "blue")
segments(12, -1.2, 22, -1.2, col = "red")
text(22, -1, "새누리", pos = 4, cex = 0.5)
text(22, -1.2, "민주", pos = 4, cex = 0.5)
points(60, -0.7, cex = 0.6, pch = 25, col = "#FF0000AA", bg = "#FF0000AA")
points(62, -0.7, cex = 0.6, pch = 25, col = "#0000FFAA", bg = "#0000FFAA")
text(63, -1, "Election Results", pos = 4, cex = 0.7)

plot of chunk unnamed-chunk-1