Un primer vistazo a las elecciones presidenciales (Segunda vuelta)

Estos son los departamentos donde triunfo Santos:

##                 DEP     JMS     OIZ Ninguno PropJMS PropOIZ PropNinguno
## 4         Atlántico  541455  139462   20485    77.2    19.9         2.9
## 11            Cauca  310642  107650   23954    70.2    24.3         5.4
## 18          Guajira  120053   46093    4990    70.2    26.9         2.9
## 33           Vaupés    4149    1645     181    69.4    27.5         3.0
## 21        Magdalena  258711  117491   11303    66.8    30.3         2.9
## 25         Putumayo   57874   26397    4571    65.1    29.7         5.1
## 23           Nariño  342699  163978   25399    64.4    30.8         4.8
## 16          Córdoba  376174  206281   17178    62.7    34.4         2.9
## 13            Chocó   60689   32489    6159    61.1    32.7         6.2
## 32            Valle  827433  459820   99638    59.7    33.2         7.2
## 12            Cesar  200452  123556   12506    59.6    36.7         3.7
## 30            Sucre  199249  126955   10022    59.3    37.8         3.0
## 6           Bolívar  309534  211983   19010    57.3    39.2         3.5
## 17          Guainía    4274    3356     313    53.8    42.3         3.9
## 28        SanAndrés    5781    4714     485    52.7    42.9         4.4
## 29        Santander  428952  347962   52450    51.7    42.0         6.3
## 5            Bogotá 1337349 1075638  213922    50.9    40.9         8.1
## 24 NortedeSantander  239215  219904   29336    49.0    45.0         6.0
## 3            Arauca   37892   36320    4099    48.4    46.4         5.2

plot of chunk unnamed-chunk-3

library(RCurl)
library(reshape2)
library(ggplot2)
library(sqldf)
options(scipen = 11111)
url <- getURL("https://raw.githubusercontent.com/finiterank/elecciones-congreso/master/resultados.presidenciales/votos-segunda-municipios2014-06-15.20.19.37.csv")
elecciones2014 <- read.csv(text = url)
clases = rep(NA, 11)
clases[1:2] = rep("character", 2)
clases[10:11] = rep("character", 2)
names(elecciones2014)[6] = "SINMARCA"
cons1 = sqldf("select DEP, sum(JMS)  as 'JMS', sum(OIZ)  as 'OIZ',\nsum(BLANCOS) as 'BLANCOS', sum(SINMARCA) as 'SINMARCA', sum(NULOS) as 'NULOS', \nsum(TOTAL) as 'TOTAL'\nfrom elecciones2014 group by DEP")
cons1$Ninguno = cons1$BLANCOS + cons1$SINMARCA + cons1$NULOS
cons1$BLANCOS = NULL
cons1$SINMARCA = NULL
cons1$NULOS = NULL
cons1$BLANCOS = NULL
cons1$TOTAL = NULL
cons2 = melt(cons1, id.vars = "DEP")
colnames(cons2)[2] = "Candidato"
colnames(cons2)[3] = "Frec"
cons2$DEP <- reorder(cons2$DEP, -cons2$Frec)
cons3 = cons1[cons1$JMS > cons1$OIZ, ]
cons3$PropJMS = round(100 * cons3$JMS/(cons3$JMS + cons3$OIZ + cons3$Ninguno), 
    1)
cons3$PropOIZ = round(100 * cons3$OIZ/(cons3$JMS + cons3$OIZ + cons3$Ninguno), 
    1)
cons3$PropNinguno = round(100 * cons3$Ninguno/(cons3$JMS + cons3$OIZ + cons3$Ninguno), 
    1)
cons3[order(cons3$PropJMS, decreasing = T), ]
g = ggplot(cons2, aes(DEP, Frec, fill = Candidato)) + geom_bar(stat = "identity") + 
    scale_fill_brewer(palette = "Set1") + theme(axis.text.x = element_text(angle = 90, 
    hjust = 1))
g

José Fernando Zea