File:QC polling 41st election.svg
Page contents not supported in other languages.
Tools
Actions
General
In other projects
Appearance
Size of this PNG preview of this SVG file: 800 × 533 pixels. Other resolutions: 320 × 213 pixels | 640 × 427 pixels | 1,024 × 683 pixels | 1,280 × 853 pixels | 2,560 × 1,707 pixels | 810 × 540 pixels.
Original file (SVG file, nominally 810 × 540 pixels, file size: 270 KB)
This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Summary
DescriptionQC polling 41st election.svg |
English: A combination of opinion polls for the 2014 Quebec general election. The trend lines are local regressions with α = 0.45 and 95% confidence interval ribbons. Election results are represented by diamonds. |
Date | |
Source | Own work |
Author | Abjiklam |
Licensing
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
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)
#get the tables from the url
theurl <- getURL("https://en.wikipedia.org/wiki/Quebec_general_election,_2014", ssl.verifyPeer=FALSE)
table.1 <- htmltab(theurl, which=12)[, c(2, 4:10)]
table.2 <- htmltab(theurl, which=13)[, c(2, 4:10)]
names(table.2) <- names(table.1)
df <- rbind(table.1[-nrow(table.1), ], table.2)
names(df)[1] <- "Date"
party.colours <- c("#9999ff", "#dd0000", "#9900cc", "#ff8800", "#666666")
#format numerical and date data
df[is.na(df)] <- 0
df$Date <- as.Date(substr(df$Date, 9, 18))
for (i in c(2:8)) {
df[[i]] = as.numeric(df[[i]])/100
}
df$Other <- df$Other + df$ON + df$GPQ
df <- df[, -c(6:7)]
#reshape data to have candidate and support as variable
mdata <- melt(df[-c(1, nrow(df)), ], id=c("Date"))
names(mdata)[2:3] <- c("Party", "Support")
election.2012 <- melt(df[nrow(df), ], id=c("Date"))
names(election.2012)[2:3] <- c("Party", "Support")
election.2014 <- melt(df[1, ], id=c("Date"))
names(election.2014)[2:3] <- c("Party", "Support")
#make plot
d <- ggplot(mdata, aes(x=Date, y=Support, colour=Party))
d <- d + geom_vline(xintercept=as.numeric(as.Date("2014-03-05")), linetype=2, color="#666666", show.legend=F)
d <- d + geom_point(alpha=0.5)
d <- d + geom_smooth(span=0.45, size=0.8, alpha=0.3, se=TRUE, show.legend=FALSE)
d <- d + scale_colour_manual(values=party.colours)
d <- d + labs(title="Opinion polls for the 2014 Quebec general election")
d <- d + scale_y_continuous(breaks=seq(0,1,0.05),
minor_breaks=seq(0,1,0.01),
labels=percent,
limits=c(0, 0.45))
d <- d + scale_x_date(labels=c("2012 Election",
format(seq(as.Date("2012-10-01"), as.Date("2014-02-01"), by="month"),
format="%b %Y"),
"Campaign",
"2014 Election"),
breaks=c(as.Date("2012-09-04"),
seq(as.Date("2012-10-01"), as.Date("2014-02-01"), by="month"),
as.Date("2014-03-05"), as.Date("2014-04-07")),
minor_breaks=NULL)
d <- d + geom_point(data=election.2014, shape=5, size=5, show.legend=FALSE)
d <- d + geom_point(data=election.2014, size=2.5, show.legend=TRUE)
d <- d + geom_text(data=election.2014, show.legend=F,
aes(label=sprintf("%.1f", election.2014$Support*100)),
size=3.5, nudge_x=11, hjust=0, color="#000000")
d <- d + geom_point(data=election.2012, shape=5, size=5, show.legend=FALSE)
d <- d + geom_point(data=election.2012, size=2.5, show.legend=FALSE)
d <- d + geom_text(data=election.2012, show.legend=F,
aes(label=sprintf("%.1f", election.2012$Support*100)),
size=3.5, nudge_x=11, nudge_y=c(0.005,-0.005,0,0,0), hjust=0, color="#000000")
d <- d + theme(panel.grid.minor=element_line(size=0.2),
panel.grid.major=element_line(size=0.6))
d <- d + theme(axis.text.x=element_text(angle=45, hjust=1))
#save plot as "qc2014.svg"
svg(filename="qc2014.svg",
width=9,
height=6,
pointsize=12,
bg="transparent")
d
dev.off()
Items portrayed in this file
depicts
20 October 2016
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 21:46, 20 October 2016 | 810 × 540 (270 KB) | Χ | cosmetic change | |
13:16, 20 October 2016 | 810 × 450 (268 KB) | Χ | User created page with UploadWizard |
File usage
The following page uses this file:
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
Width | 648pt |
---|---|
Height | 432pt |
Retrieved from "https://en.wikipedia.org/wiki/File:QC_polling_41st_election.svg"