File:QC polling 42nd election.svg

Original file(SVG file, nominally 810 × 540 pixels, file size: 248 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary

edit
Description
English: A combination of opinion polls for the 42nd 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

edit
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
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, 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/42nd_Quebec_general_election", ssl.verifyPeer=FALSE)
df <- htmltab(theurl, which=7)[, c(2, 4:8)]
names(df)[1] <- "Date"
party.colours <- c("#dd0000", "#9999ff", "#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:6)) {
  df[[i]] = as.numeric(sub("*", "", df[[i]], fixed=TRUE))/100
}

#reshape data to have candidate and support as variable
mdata <- melt(df[-nrow(df), ], id=c("Date"))
names(mdata)[2:3] <- c("Party", "Support")

election.2014 <- melt(df[nrow(df), ], 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_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 since 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("2014 Election",
                               format(seq(as.Date("2014-06-01"), as.Date("2018-10-01"), by="2 month"),
                                      format="%b %Y")),
                      breaks=c(as.Date("2014-04-07"),
                               seq(as.Date("2014-06-01"), as.Date("2018-10-01"), by="2 month")),
                      minor_breaks=seq(as.Date("2014-05-01"), as.Date("2018-10-01"), by="month"))

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=-15, hjust=1, 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 "qc2018.svg"
svg(filename="qc2018.svg", 
    width=9, 
    height=6, 
    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/TimeThumbnailDimensionsUserComment
current21:45, 20 October 2016Thumbnail for version as of 21:45, 20 October 2016810 × 540 (248 KB)Χ (talk | contribs)cosmetic change
13:36, 20 October 2016Thumbnail for version as of 13:36, 20 October 2016810 × 450 (246 KB)Χ (talk | contribs)User created page with UploadWizard

There are no pages that use this file.

Metadata