These data are sourced from the 16th Official Canvass Report from the Comelec Rappler Mirror Server. Retrieved May 23, 2013 4:30am. http://bit.ly/12AmEyO
you may also download the high-res dataviz from dropbox --> http://bit.ly/1a9KBPU
The following source code for making the heatmaps is working and functional in R v. 3.0.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | #this code was tested in # R version 3.0.0 (2013-04-03) -- "Masked Marvel" # Copyright (C) 2013 The R Foundation for Statistical Computing # Platform: i386-w64-mingw32/i386 (32-bit) getwd() # this is your working directory # setwd("") # you can set your personal working directory here getwd() # ------------------------------------------------------------------------------------------------ # # LOAD VOTES DATASETS from COMELEC's 16th canvass report (OFFICIAL TALLY) # Accessed from http://www.rappler.com/nation/politics/elections-2013/features/rich-media/29126-official-tally-votes-2013-senatorial-race # Retrieved May 23, 2013 4:30am data1 <- "http://dl.dropboxusercontent.com/u/7911075/election%202013%20csv/namebyregion.csv" download.file(data1, destfile="./datasets/namebyregion.csv") data2 <- "http://dl.dropboxusercontent.com/u/7911075/election%202013%20csv/namebyprovince.csv" download.file(data2, destfile="./datasets/namebyprovince.csv") data3 <- "http://dl.dropboxusercontent.com/u/7911075/election%202013%20csv/provincetotalbyname.csv" download.file(data3, destfile="./datasets/provincetotalbyname.csv") data4 <- "http://dl.dropboxusercontent.com/u/7911075/election%202013%20csv/regiontotalbyname.csv" download.file(data4, destfile="./datasets/regiontotalbyname.csv") list.files(".") dateDownloaded <-date() dateDownloaded byregion <- read.csv("./datasets/namebyregion.csv", header=TRUE) str(byregion) byprovince <- read.csv("./datasets/namebyprovince.csv", header=TRUE) str(byprovince) tprovince <- read.csv("./datasets/provincetotalbyname.csv", header=TRUE) str(tprovince) tregion <- read.csv("./datasets/regiontotalbyname.csv", header=TRUE) str(tregion) # ------------------------------------------------------------------------------------------------ # # LOAD COLOR PALETTES library(RColorBrewer) cols4v1 <- brewer.pal(5, "YlGnBu") pal4v1 <- colorRampPalette(cols4v1) # <- dark blue cyan white gradient cols4v2 <- brewer.pal(5, "YlOrBr") pal4v2 <- colorRampPalette(cols4v2) # <- brown orange white gradient cols4v3 <- brewer.pal(5, "PuRd") pal4v3 <- colorRampPalette(cols4v3) # <- purple pink white gradient cols4v4 <- brewer.pal(5, "RdPu") pal4v4 <- colorRampPalette(cols4v4) # <- violet pink white gradient cols8 <- brewer.pal(8, "Set3") pal8 <- colorRampPalette(cols8) cols12 <- brewer.pal(12, "Set3") pal12 <- colorRampPalette(cols12) # ------------------------------------------------------------------------------------------------ # # DRAW HEATMAPS FOR REGION row.names(byregion) <- byregion$X byregion <- byregion[,2:19] byregion_matrix <- data.matrix(byregion) regions_heatmap1 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) # <-- pink, blue regions_heatmap2 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = heat.colors(256), scale="column", margins=c(5,10)) # <-- too much red regions_heatmap3 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = pal4v2(5), scale="column", margins=c(5,10)) # <-- yellow brown gradient regions_heatmap4 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient regions_heatmap5 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = pal12(5), scale="column", margins=c(5,10)) # <- messy looking regions_heatmap6 <- heatmap(byregion_matrix, Rowv=NA, Colv=NA, col = pal4v4(5), scale="column", margins=c(5,10)) # <-- purle pink gradient # dev.copy2pdf(file="./output/votesperregion.pdf", height = 8, width = 11) # ------------------------------------------------------------------------------------------------ # # DRAW HEATMAPS PER PROVINCE str(byprovince) names(byprovince) # REGION 1 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region1 provincesregion1 <- byprovince[,33:37] provincesregion1$X <- byprovince$X str(provincesregion1) row.names(provincesregion1) <- provincesregion1$X provincesregion1 <- provincesregion1[,1:5] provincesregion1_matrix <- data.matrix(provincesregion1) #draw heatmap for provinces in region1 region1_heatmap <- heatmap(provincesregion1_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient dev.copy2pdf(file="./output/votesregion1.pdf", height = 8, width = 11) # REGION 2 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region2 provincesregion2 <- byprovince[,38:43] provincesregion2$X <- byprovince$X str(provincesregion2) row.names(provincesregion2) <- provincesregion2$X provincesregion2 <- provincesregion2[,1:6] provincesregion2_matrix <- data.matrix(provincesregion2) #draw heatmap for provinces in region2 region2_heatmap <- heatmap(provincesregion2_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion2.pdf", height = 8, width = 11) # REGION 3 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region3 provincesregion3 <- byprovince[,44:51] provincesregion3$X <- byprovince$X str(provincesregion3) row.names(provincesregion3) <- provincesregion3$X provincesregion3 <- provincesregion3[,1:8] provincesregion3_matrix <- data.matrix(provincesregion3) #draw heatmap for provinces in region3 region3_heatmap <- heatmap(provincesregion3_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion3.pdf", height = 8, width = 11) # REGION 4A ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region4a provincesregion4a <- byprovince[,52:57] provincesregion4a$X <- byprovince$X str(provincesregion4a) row.names(provincesregion4a) <- provincesregion4a$X provincesregion4a <- provincesregion4a[,1:6] provincesregion4a_matrix <- data.matrix(provincesregion4a) #draw heatmap for provinces in region4a region4a_heatmap <- heatmap(provincesregion4a_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion4a.pdf", height = 8, width = 11) # REGION4B ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region4b provincesregion4b <- byprovince[,58:63] provincesregion4b$X <- byprovince$X str(provincesregion4b) row.names(provincesregion4b) <- provincesregion4b$X provincesregion4b <- provincesregion4b[,1:6] provincesregion4b_matrix <- data.matrix(provincesregion4b) #draw heatmap for provinces in region4b region4b_heatmap <- heatmap(provincesregion4b_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion4b.pdf", height = 8, width = 11) # REGION5 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region5 provincesregion5 <- byprovince[,64:70] provincesregion5$X <- byprovince$X str(provincesregion5) row.names(provincesregion5) <- provincesregion5$X provincesregion5 <- provincesregion5[,1:7] provincesregion5_matrix <- data.matrix(provincesregion5) #draw heatmap for provinces in region5 region5_heatmap <- heatmap(provincesregion5_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion5.pdf", height = 8, width = 11) # REGION6 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region6 provincesregion6 <- byprovince[,71:79] provincesregion6$X <- byprovince$X str(provincesregion6) row.names(provincesregion6) <- provincesregion6$X provincesregion6 <- provincesregion6[,1:9] provincesregion6_matrix <- data.matrix(provincesregion6) #draw heatmap for provinces in region6 region6_heatmap <- heatmap(provincesregion6_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion6.pdf", height = 8, width = 11) # REGION7 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region7 provincesregion7 <- byprovince[,80:86] provincesregion7$X <- byprovince$X str(provincesregion7) row.names(provincesregion7) <- provincesregion7$X provincesregion7 <- provincesregion7[,1:7] provincesregion7_matrix <- data.matrix(provincesregion7) #draw heatmap for provinces in region7 region7_heatmap <- heatmap(provincesregion7_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion7.pdf", height = 8, width = 11) # REGION8 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region8 provincesregion8 <- byprovince[,87:93] provincesregion8$X <- byprovince$X str(provincesregion8) row.names(provincesregion8) <- provincesregion8$X provincesregion8 <- provincesregion8[,1:7] provincesregion8_matrix <- data.matrix(provincesregion8) #draw heatmap for provinces in region8 region8_heatmap <- heatmap(provincesregion8_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion8.pdf", height = 8, width = 11) # REGION9 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region9 provincesregion9 <- byprovince[,94:98] provincesregion9$X <- byprovince$X str(provincesregion9) row.names(provincesregion9) <- provincesregion9$X provincesregion9 <- provincesregion9[,1:5] provincesregion9_matrix <- data.matrix(provincesregion9) #draw heatmap for provinces in region9 region9_heatmap <- heatmap(provincesregion9_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion9.pdf", height = 8, width = 11) # REGION10 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region10 provincesregion10 <- byprovince[,99:106] provincesregion10$X <- byprovince$X str(provincesregion10) row.names(provincesregion10) <- provincesregion10$X provincesregion10 <- provincesregion10[,1:7] provincesregion10_matrix <- data.matrix(provincesregion10) #draw heatmap for provinces in region10 region10_heatmap <- heatmap(provincesregion10_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion10.pdf", height = 8, width = 11) # REGION11 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region11 provincesregion11 <- byprovince[,107:112] provincesregion11$X <- byprovince$X str(provincesregion11) row.names(provincesregion11) <- provincesregion11$X provincesregion11 <- provincesregion11[,1:6] provincesregion11_matrix <- data.matrix(provincesregion11) #draw heatmap for provinces in region11 region11_heatmap <- heatmap(provincesregion11_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion11.pdf", height = 8, width = 11) # REGION12 ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region12 provincesregion12 <- byprovince[,113:117] provincesregion12$X <- byprovince$X str(provincesregion12) row.names(provincesregion12) <- provincesregion12$X provincesregion12 <- provincesregion12[,1:5] provincesregion12_matrix <- data.matrix(provincesregion12) #draw heatmap for provinces in region12 region12_heatmap <- heatmap(provincesregion12_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion12.pdf", height = 8, width = 11) # REGION13 CARAGA ------------------------------------------------------------------------------------------------ # for example, we take the provinces in region13 provincesregion13 <- byprovince[,10:15] provincesregion13$X <- byprovince$X str(provincesregion13) row.names(provincesregion13) <- provincesregion13$X provincesregion13 <- provincesregion13[,1:6] provincesregion13_matrix <- data.matrix(provincesregion13) #draw heatmap for provinces in region13 region13_heatmap <- heatmap(provincesregion13_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesregion13.pdf", height = 8, width = 11) # NCR ------------------------------------------------------------------------------------------------ # for example, we take the provinces in ncr provincesncr <- byprovince[,16:32] provincesncr$X <- byprovince$X str(provincesncr) row.names(provincesncr) <- provincesncr$X provincesncr <- provincesncr[,1:17] provincesncr_matrix <- data.matrix(provincesncr) #draw heatmap for provinces in ncr ncr_heatmap <- heatmap(provincesncr_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesncr.pdf", height = 8, width = 11) # CAR ------------------------------------------------------------------------------------------------ # for example, we take the provinces in car provincescar <- byprovince[,2:9] provincescar$X <- byprovince$X str(provincescar) row.names(provincescar) <- provincescar$X provincescar <- provincescar[,1:8] provincescar_matrix <- data.matrix(provincescar) #draw heatmap for provinces in car car_heatmap <- heatmap(provincescar_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votescar.pdf", height = 8, width = 11) # ARMM ------------------------------------------------------------------------------------------------ # for example, we take the provinces in armm provincesarmm <- byprovince[,118:123] provincesarmm$X <- byprovince$X str(provincesarmm) row.names(provincesarmm) <- provincesarmm$X provincesarmm <- provincesarmm[,1:6] provincesarmm_matrix <- data.matrix(provincesarmm) #draw heatmap for provinces in armm armm_heatmap <- heatmap(provincesarmm_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesarmm.pdf", height = 8, width = 11) # OAV OVERSEAS ABSENTEE VOTING COUNTRIES ------------------------------------------------------------------------------------------------ # for example, we take the provinces in oav provincesoav <- byprovince[,124:146] provincesoav$X <- byprovince$X str(provincesoav) row.names(provincesoav) <- provincesoav$X provincesoav <- provincesoav[,1:23] provincesoav_matrix <- data.matrix(provincesoav) #draw heatmap for provinces in oav oav_heatmap <- heatmap(provincesoav_matrix, Rowv=NA, Colv=NA, col = pal4v1(5), scale="column", margins=c(5,10)) # <-- yellow blue gradient # dev.copy2pdf(file="./output/votesoav.pdf", height = 8, width = 11) # # --------------------------- # END OF CODE |
No comments:
Post a Comment