Ver código
# Paquetes ####
library(tidyverse)
library(plotly)
voto_blanco_2018 <- readr::read_csv("https://raw.githubusercontent.com/nelsonamayad/Elecciones-presidenciales-2018/master/Elecciones%202018/encuestas2018.csv") %>%
dplyr::rename(ns_nr=`ns/nr`) %>%
tidyr::pivot_longer(cols = c(ivan_duque,german_vargas_lleras,humberto_delacalle,sergio_fajardo,gustavo_petro),
names_to = "candidato",
values_to = "int_voto") %>%
#Standarize
dplyr::mutate(blanco_std = (blanco-mean(blanco)/sd(blanco))) %>%
dplyr::group_by(candidato) %>%
dplyr::mutate(int_voto_std = (int_voto-mean(int_voto)/sd(int_voto))) %>%
dplyr::mutate(vuelta = ifelse(n<27,0,1)) %>%
dplyr::filter(n>11)
#Resultados
#dplyr::bind_rows(tribble(~fecha,~ivan_duque,~gustavo_petro,~blanco,~encuestadora,
# lubridate::as_date("2018-06-17"),54,42,4,"Resultado"))
voto_blanco_2018_plot <- voto_blanco_2018 %>%
ggplot(aes(x=lubridate::as_date(fecha),y=blanco))+
geom_point(aes(shape=encuestadora,
text = paste('Voto en blanco:', blanco,
'<br>Muestra:',muestra,
'<br>Encuestadora:',encuestadora,
'<br>Fecha:', fecha)),
position = "jitter",
size=3,
color="black",
show.legend = FALSE)+
geom_point(data=tribble(~fecha,~ivan_duque,~gustavo_petro,~blanco,~encuestadora,
lubridate::as_date("2018-05-27"),39.34,25.08,1.7,"Resultado",
lubridate::as_date("2018-06-17"),54,42,4,"Resultado"),
aes(shape=encuestadora,
text = paste('Voto en blanco:', blanco,
'<br>Resultado:',encuestadora,
'<br>Fecha:', fecha)),
#position = "jitter",
size=8,
color="red",
show.legend = FALSE)+
#geom_hline(yintercept = 338581/19336134, linetype="dashed", color="orangered2")+
#geom_hline(yintercept = 807924/19247062, linetype="dashed",color="forestgreen")+
# Vueltas
geom_vline(xintercept = c(as.numeric(lubridate::as_date("2018-03-11")),
as.numeric(lubridate::as_date("2018-05-27")),
as.numeric(lubridate::as_date("2018-06-17"))), color="royalblue2")+
#annotate("text",x=lubridate::as_date("2018-02-27"),y=29,label="Legislativas", angle=90,color="royalblue2")+
#annotate("text",x=lubridate::as_date("2018-05-16"),y=29,label="1 vuelta", angle=90,color="royalblue2")+
#annotate("text",x=lubridate::as_date("2018-06-10"),y=29,label="2 vuelta", angle=90,color="royalblue2")+
# LOESS
geom_smooth(method="loess",color="white",size=3,fill="grey10")+
scale_shape_manual(values=c(4,16,17,3,15,25,10,11,8))+
scale_x_date(date_breaks = "1 week")+
labs(x=NULL,y="% voto en blanco reportado en cada encuesta")+
theme_classic()+
theme(legend.position="none",
legend.title = element_blank(),
#panel.background = element_rect(),
axis.text.x=element_text(angle=90, hjust=1, size=6))
ggplotly(voto_blanco_2018_plot, tooltip = "text")El voto en blanco en las encuestas de 2018