File:Nationwide polls for the 2016 Democratic Party presidential primaries.svg
Size of this PNG preview of this SVG file: 800 × 444 pixels. Other resolutions: 320 × 178 pixels | 640 × 356 pixels | 1,024 × 569 pixels | 1,280 × 711 pixels | 2,560 × 1,422 pixels | 810 × 450 pixels.
Original file (SVG file, nominally 810 × 450 pixels, file size: 232 KB)
File information
Structured data
Captions
Summary edit
DescriptionNationwide polls for the 2016 Democratic Party presidential primaries.svg |
English: A combination of nationwide opinion polls during the 2016 Democratic Party presidential primaries. The trend lines are Local Regressions with α = 0.8 and 95% confidence interval ribbons. The point sizes and trend lines are weighted according to the margin of error of each poll. |
Date | |
Source | Own work |
Author | Abjiklam |
Licensing edit
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Code edit
The graph is generated by the following R script, largely inspired by this file.
library(RCurl)
library(reshape)
library(htmltab)
library(ggplot2)
library(stringr)
library(scales)
#get the table from the url
theurl <- getURL("https://en.wikipedia.org/wiki/Nationwide_opinion_polling_for_the_Democratic_Party_2016_presidential_primaries", ssl.verifyPeer=FALSE)
table <- htmltab(theurl, which=3)
table2 <- htmltab(theurl, which=4)
table = table[,1:6]
table2 = table2[,c(1:5,7)]
names(table) <- c("Source", "Size", "Error", "Date", "Clinton", "Sanders")
names(table2) <- names(table)
df = rbind(table, table2)
for (i in c(3, 5:7)) {
df[[i]] = as.numeric(sub("%", "", df[[i]]))/100
}
df$Date = sub("[0-9]+\\s*–\\s*([0-9]+)", "\\1", df$Date)
df$Date = sub(".*–", "", df$Date)
df$Date = sub("[0-9]+\\s*-\\s*([0-9]+)", "\\1", df$Date)
df$Date = sub(".*-", "", df$Date)
df$Date = trimws(df$Date)
df$Date = as.Date(df$Date, format="%B %d, %Y")
df$Size = as.numeric(sub(",", "", df$Size))
df$Error = 1/sqrt(df$Size)
mdata <- melt(df, id=c("Date", "Source", "Error", "Size"))
names(mdata)[5:6] = c("Candidate", "Support")
colors = c("#D4AA00", "#228b22")
labels = c("Clinton", "Sanders")
results = mdata
#breaks() returns n evenly spaced numbers between x and y
#whose squares are divisible by p
#the function is used for the legend
breaks <- function(x, y, n, p) {
x = sqrt(ceiling(as.integer(x^2) / p) * p)
y = sqrt(floor(as.integer(y^2) / p) * p)
s = seq(x, y, length.out=n)
for (i in 2:(n-1)) {
s[i] = sqrt(round(s[i]^2 / p) * p)
}
return(unique(s))
}
d = ggplot(results, aes(x=Date, y=Support, colour=Candidate, size=1/Error, weight=1/Error)) +
geom_point(alpha=0.7) +
geom_smooth(span=0.8, show.legend=F) +
scale_colour_manual(values = colors) +
labs(title="Nationwide opinion polling for the 2016 Democratic Party primaries") +
scale_size_area(max_size=3,
breaks=function(x) breaks(x[1], x[2], 5, 100), #5 numbers divisible by 100
labels=function(x) comma_format()(x^2),
name="Sample Size") +
scale_y_continuous(breaks=seq(0,1,0.1), minor_breaks=seq(0,1,0.02),
labels=percent, limits=c(0.2,0.7)) +
scale_x_date(labels=date_format("%b %d"),
breaks=sort(c(seq(as.Date("2016/1/1"), as.Date("2016/7/28"), "month"),
seq(as.Date("2016/1/15"), as.Date("2016/7/28"), "month"),
as.Date("2016/7/28"))),
limits=c(as.Date("2016/1/1"), as.Date("2016/7/28"))) +
theme(panel.grid.minor=element_line(size=0.2),
panel.grid.major=element_line(size=0.6))
#save plot as "dp.svg"
svg(filename="dp.svg",
width=9,
height=5,
pointsize=12,
bg="transparent")
d
dev.off()
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 16:32, 29 June 2016 | 810 × 450 (232 KB) | Χ (talk | contribs) | update | |
14:10, 8 June 2016 | 810 × 450 (228 KB) | Χ (talk | contribs) | update | ||
11:57, 6 June 2016 | 810 × 360 (226 KB) | Χ (talk | contribs) | update | ||
03:41, 31 May 2016 | 810 × 360 (223 KB) | Χ (talk | contribs) | better sample size legend | ||
04:33, 30 May 2016 | 810 × 360 (220 KB) | Χ (talk | contribs) | kept only major candidates (as was done for the republican graph) | ||
15:50, 29 May 2016 | 810 × 360 (238 KB) | Χ (talk | contribs) | update | ||
14:42, 22 May 2016 | 810 × 360 (233 KB) | Χ (talk | contribs) | update | ||
22:24, 16 May 2016 | 810 × 360 (231 KB) | Χ (talk | contribs) | update | ||
17:42, 8 May 2016 | 810 × 360 (229 KB) | Χ (talk | contribs) | update | ||
12:36, 2 May 2016 | 810 × 360 (225 KB) | Χ (talk | contribs) | update |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on da.wikipedia.org
- Usage on en.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Width | 648pt |
---|---|
Height | 360pt |