Archivo:Trump vs. Clinton nationwide.svg

Contenido de la página no disponible en otros idiomas.
De Wikipedia, la enciclopedia libre

Ver la imagen en su resolución original((Imagen SVG, nominalmente 810 × 360 pixels, tamaño de archivo: 263 kB))

Resumen

Descripción
English: A plot of opinion polls for the Clinton vs. Trump race for the 2016 U.S. presidential election. Covers the last three months or the period after the conventions, whichever date is earlier. The trend lines are local regressions weighted by sample size with span α=0.8.
Fecha
Fuente Trabajo propio
Autor Abjiklam

Licencia

Yo, el titular de los derechos de autor de esta obra, la publico en los términos de la siguiente licencia:
w:es:Creative Commons
atribución compartir igual
Este archivo está disponible bajo la licencia Creative Commons Attribution-Share Alike 4.0 International.
Eres libre:
  • de compartir – de copiar, distribuir y transmitir el trabajo
  • de remezclar – de adaptar el trabajo
Bajo las siguientes condiciones:
  • atribución – Debes otorgar el crédito correspondiente, proporcionar un enlace a la licencia e indicar si realizaste algún cambio. Puedes hacerlo de cualquier manera razonable pero no de manera que sugiera que el licenciante te respalda a ti o al uso que hagas del trabajo.
  • compartir igual – En caso de mezclar, transformar o modificar este trabajo, deberás distribuir el trabajo resultante bajo la misma licencia o una compatible como el original.

Code

The graph is generated by the following R script, inspired by this file.

library(RCurl)
library(reshape)
library(htmltab)
library(ggplot2)
library(stringr)
library(scales)
library(lubridate)

#set these variables to TRUE/FALSE to toggle trend lines
daily.average = FALSE #bumpy daily average
smooth.average = FALSE #smoothed average using local regression

#get the tables from the url
theurl <- getURL("https://en.wikipedia.org/wiki/Nationwide_opinion_polling_for_the_United_States_presidential_election,_2016", ssl.verifyPeer=FALSE)
table1 <- htmltab(theurl, which=3)
table2 <- htmltab(theurl, which=4)

#"since convention nominations" table
table1 <- table1[, c(1, 2, 6, 3, 4)]
names(table1) <- c("Source", "Date", "Size", "DP", "RP")

#"Polls conducted in 2016" table
table2 <- table2[, c(1, 2, 8, 3:6)]
names(table2) <- c("Source", "Date", "Size", "DC", "DP", "RC", "RP")
table2 <- table2[which(table2$DC=="Hillary Clinton" & table2$RC=="Donald Trump"), c(1:3, 5, 7)]

#merge tables
df <- rbind(table1, table2)
names(df)[4:5] <- c("Clinton", "Trump")

#format numerical and date data
for (i in 4:5) {
  df[[i]] <- as.numeric(sub("%", "", df[[i]]))/100
}

df$Size <- as.numeric(sub(",", "", df$Size))

df$Date <- sub("[0-9]+\\s*(–|-)\\s*([0-9]+)", "\\2", df$Date)
df$Date <- sub(".*(–|-)", "", df$Date)
df$Date <- trimws(df$Date)
df$Date <- as.Date(df$Date, format="%B %d, %Y")

#only keep polls as far as 3 months ago or after conventions
df <- df[which(df$Date >= min(max(df$Date)-months(3), as.Date("2016-07-28"))),]

#reshape data to have candidate and support as variable
mdata <- melt(df, id=c("Date", "Source", "Size"))
names(mdata)[4:5] <- c("Candidate", "Support")

colors <- c("#3333FF", "#FF3333")
labels <- c("Clinton", "Trump")

results <- mdata

#make plot
d <- ggplot(results, aes(x=Date, y=Support, colour=Candidate))
d <- d + geom_point(aes(size=Size), alpha=0.5)
#optional smooth average computation and display
if(smooth.average) {
  d <- d + geom_smooth(aes(weight=Size), span=0.6, size=0.8, se=TRUE)
}
#optional daily average computation and display
if(daily.average) {
  average <- function(dataframe, date, candidate) {
    return(with(dataframe[which(dataframe$Date==as.Date(date) & dataframe$Candidate==candidate),], weighted.mean(Support, Size)))
  }
  dates <- unique(df$Date)
  avg.results <- data.frame(Date=rep(dates, 2),
                            Candidate=c(
                              rep("Clinton", length(dates)),
                              rep("Trump", length(dates))
                            ),
                            Support=c(
                              as.double(lapply(dates, function(x) average(results, x, "Clinton"))),
                              as.double(lapply(dates, function(x) average(results, x, "Trump")))
                            ))
  
  d <- d + geom_line(data=avg.results, size=0.8)
}
d <- d + scale_colour_manual(values = colors)
d <- d + labs(title="Nationwide opinion polling for the 2016 U.S. presidential election")
d <- d + scale_size_area(max_size=15,
                         breaks=c(1000, 2000, 4000, 8000, 16000),
                         labels=function(x) comma_format()(x),
                         name="Sample Size")
d <- d + scale_y_continuous(breaks=seq(0,1,0.05),
                            minor_breaks=seq(0,1,0.01),
                            labels=percent,
                            limits=c(0.3, 0.55))
d <- d + scale_x_date(labels=date_format("%b %d"),
                      breaks=date_breaks("weeks"),
                      minor_breaks=date_breaks("days"))
d <- d + theme(panel.grid.minor=element_line(size=0.2),
               panel.grid.major=element_line(size=0.6))

#save plot as "ct.svg"
svg(filename="ct.svg", 
    width=9, 
    height=4, 
    pointsize=12,
    bg="transparent")
d
dev.off()

Leyendas

Añade una explicación corta acerca de lo que representa este archivo

Elementos representados en este archivo

representa a

Historial del archivo

Haz clic sobre una fecha y hora para ver el archivo tal como apareció en ese momento.

(recientes · primeras) Ver (10 siguientes · ) (10 · 20 · 50 · 100 · 250 · 500).
Fecha y horaMiniaturaDimensionesUsuarioComentario
actual17:46 7 oct 2016Miniatura de la versión del 17:46 7 oct 2016810 × 360 (263 kB)Χupdate
14:20 2 oct 2016Miniatura de la versión del 14:20 2 oct 2016810 × 360 (260 kB)Χupdate
16:15 24 sep 2016Miniatura de la versión del 16:15 24 sep 2016810 × 360 (255 kB)Χno regression, larger dots
14:08 14 sep 2016Miniatura de la versión del 14:08 14 sep 2016810 × 360 (246 kB)Χparam
14:02 14 sep 2016Miniatura de la versión del 14:02 14 sep 2016810 × 360 (246 kB)Χback to local regression
18:02 18 ago 2016Miniatura de la versión del 18:02 18 ago 2016810 × 360 (227 kB)Χthicker lines
17:58 18 ago 2016Miniatura de la versión del 17:58 18 ago 2016810 × 360 (227 kB)Χwith daily average
17:55 18 ago 2016Miniatura de la versión del 17:55 18 ago 2016810 × 360 (224 kB)Χupdate
11:42 11 ago 2016Miniatura de la versión del 11:42 11 ago 2016810 × 360 (223 kB)Χupdate. now automatically covers the last 3 months or the post-convention period, whichever is longest.
09:25 10 ago 2016Miniatura de la versión del 09:25 10 ago 2016810 × 360 (226 kB)Χremoved trend line pending discussion. start graph on May 1, will eventually limit the time span to after national conventions once enough data is available.
(recientes · primeras) Ver (10 siguientes · ) (10 · 20 · 50 · 100 · 250 · 500).

La siguiente página usa este archivo:

Uso global del archivo

Las wikis siguientes utilizan este archivo:

Metadatos