Attēls:Trump vs. Clinton nationwide.svg

Lapas saturs netiek atbalstīts citās valodās.
Vikipēdijas lapa

Sākotnējais fails(SVG fails, definētais izmērs 810 × 360 pikseļi, faila izmērs: 263 KB)

Kopsavilkums

Apraksts
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.
Datums
Avots Paša darbs
Autors Abjiklam

Licence

Es, šī darba autortiesību īpašnieks, publicēju to saskaņā ar šo licenci:
w:en:Creative Commons
atsaucoties nemainot licenci
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
Jūs varat brīvi:
  • koplietot – kopēt, izplatīt un pārraidīt darbu
  • remiksēt – pielāgot darbu
Saskaņā ar šādiem nosacījumiem:
  • atsaucoties – Tev ir jānorāda autors, saite uz licenci un to, vai veiktas kādas izmaiņas. To var darīt jebkādā saprātīgā veidā, bet ne tādā, kas norādītu, ka licencētājs atbalsta tevi vai veidu, kā tu izmanto šo darbu.
  • nemainot licenci – Ja tu miksē, pārveido vai izmanto materiālu, tev savs devums jāpublicē ar to pašu vai saderīgu licenci kā oriģināls.

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()

Captions

Pievieno vienas rindiņas aprakstu, ko šis fails attēlo

Šajā failā attēlotais

attēlo

24 maijs 2016

Faila hronoloģija

Uzklikšķini uz datums/laiks kolonnā esošās saites, lai apskatītos, kā šis fails izskatījās tad.

(Jaunākās | Senākās) Skatīt (10 jaunākas | ) (10 | 20 | 50 | 100 | 250 | 500 vienā lapā).
Datums/LaiksAttēlsIzmēriDalībnieksKomentārs
tagadējais2016. gada 7. oktobris, plkst. 20.462016. gada 7. oktobris, plkst. 20.46 versijas sīktēls810 × 360 (263 KB)Χupdate
2016. gada 2. oktobris, plkst. 17.202016. gada 2. oktobris, plkst. 17.20 versijas sīktēls810 × 360 (260 KB)Χupdate
2016. gada 24. septembris, plkst. 19.152016. gada 24. septembris, plkst. 19.15 versijas sīktēls810 × 360 (255 KB)Χno regression, larger dots
2016. gada 14. septembris, plkst. 17.082016. gada 14. septembris, plkst. 17.08 versijas sīktēls810 × 360 (246 KB)Χparam
2016. gada 14. septembris, plkst. 17.022016. gada 14. septembris, plkst. 17.02 versijas sīktēls810 × 360 (246 KB)Χback to local regression
2016. gada 18. augusts, plkst. 21.022016. gada 18. augusts, plkst. 21.02 versijas sīktēls810 × 360 (227 KB)Χthicker lines
2016. gada 18. augusts, plkst. 20.582016. gada 18. augusts, plkst. 20.58 versijas sīktēls810 × 360 (227 KB)Χwith daily average
2016. gada 18. augusts, plkst. 20.552016. gada 18. augusts, plkst. 20.55 versijas sīktēls810 × 360 (224 KB)Χupdate
2016. gada 11. augusts, plkst. 14.422016. gada 11. augusts, plkst. 14.42 versijas sīktēls810 × 360 (223 KB)Χupdate. now automatically covers the last 3 months or the post-convention period, whichever is longest.
2016. gada 10. augusts, plkst. 12.252016. gada 10. augusts, plkst. 12.25 versijas sīktēls810 × 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.
(Jaunākās | Senākās) Skatīt (10 jaunākas | ) (10 | 20 | 50 | 100 | 250 | 500 vienā lapā).

Šo failu izmanto šajā 1 lapā:

Globālais faila lietojums

Šīs Vikipēdijas izmanto šo failu:

Metadati