Jump to content

File:QC polling campaign 2014.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (SVG file, nominally 720 × 450 pixels, file size: 148 KB)

Summary

Description
English: A combination of opinion polls during the 2014 Quebec general election campaign. The trend lines are local regressions with α = 0.8 and 95% confidence interval ribbons. Election results are represented by diamonds.
Date
Source Own work
Author Abjiklam
Other versions File:QC sondages campagne 2014.svg

Licensing

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

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/Quebec_general_election,_2014", ssl.verifyPeer=FALSE)
table <- htmltab(theurl, which=12)

df = table[2:nrow(table)-1, c(2, 5, 4, 6, 7)]
names(df) = c("Date", "QLP", "PQ", "CAQ", "QS")

df$Date = as.Date(substr(df[, 1], 9, 18))

for (i in c(2:5)) {
  df[[i]] = as.numeric(df[[i]])/100
}

mdata <- melt(df[3:nrow(df)-1, ], id="Date")
names(mdata)[2:3] = c("Party", "Support")
colors = c("#EA6D6A", "#87CEFA", "#9372D4", "#FF8040")
labels = c("QLP", "PQ", "CAQ", "QS")

results = mdata
election = data.frame(Date = rep(df$Date[1], 4),
                      Support = as.numeric(df[1, 2:5]),
                      Party = labels)

d = ggplot(results, aes(x=Date, y=Support, colour=Party)) +
  geom_point(alpha=0.7) + 
  geom_smooth(span=0.8, show.legend=F, alpha=0.3) + 
  scale_colour_manual(values = colors) + 
  labs(title="Polling during the 2014 Quebec electoral campaign") + 
  scale_y_continuous(breaks=seq(0,0.5,0.05), minor_breaks=seq(0,0.5,0.01), labels=percent,
                     limits=c(0, 0.5)) + 
  scale_x_date(labels=date_format("%b %d"),
               breaks=c(seq(as.Date("2014/3/5"), as.Date("2014/4/7"), "5 days"), as.Date("2014/4/7")),
               minor_breaks=seq(as.Date("2014/3/5"), as.Date("2014/4/7"), "day"),
               limits=c(as.Date("2014/3/5"), as.Date("2014/4/7"))) +
  theme(panel.grid.minor=element_line(size=0.2),
        panel.grid.major=element_line(size=0.8)) + 
  geom_point(data=election, size=3, shape=5, show.legend=F) + 
  geom_point(data=election, size=2, show.legend=F) + 
  geom_text(data=election, show.legend=F,
            aes(label=round(election$Support*100, digits=1)),
            size=3, hjust=-0.2, vjust=-0.4, color="#000000")

#save plot as "qc2014.svg"
svg(filename="qc2014.svg", 
    width=8, 
    height=5, 
    pointsize=12,
    bg="transparent")
d
dev.off()

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

24 May 2016

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current20:13, 24 May 2016Thumbnail for version as of 20:13, 24 May 2016720 × 450 (148 KB)ΧUser created page with UploadWizard
No pages on the English Wikipedia use this file (pages on other projects are not listed).

Metadata