File:Opinion polling for the next Romanian legislative election.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 1,620 × 900 pixels, file size: 180 KB)

Captions

Captions

Add a one-line explanation of what this file represents
This file may be updated to reflect new information.
If you wish to use a specific version of the file without new updates being mirrored, please upload the required version as a separate file.

Summary[edit]

Description
English: Opinion polling for the upcoming 2024 Romanian legislative election using local regressions (LOESS)
Code template: https://gitlab.com/gbuvn1/opinion-polling-graph
ggplot.R
Sys.setlocale("LC_TIME", "English")
library(ggplot2)
library(anytime)
library(tidyverse)
library(svglite)

polls <- read.table("CAT.csv", header=T, sep=",", fileEncoding="UTF-8", stringsAsFactor=F)
polls$polldate <- as.Date(anydate(polls$polldate))

spansize <- 0.6       # general smoothing parameter for trend line
startdate <- '2020-12-06'   # date of previous election
enddate <- '2025-03-21'     # (latest) date of next election

# retrieve party names from CSV
party1 <- colnames(polls)[2]
party2 <- colnames(polls)[3]
party3 <- colnames(polls)[4]
party4 <- colnames(polls)[5]
party5 <- colnames(polls)[6]
party6 <- colnames(polls)[7]
party7 <- colnames(polls)[8]
party8 <- colnames(polls)[9]
party9 <- colnames(polls)[10]
party10 <- colnames(polls)[11]
party11 <- colnames(polls)[12]
party12 <- colnames(polls)[13]

# define party colors (taken from https://en.wikipedia.org/wiki/Category:Germany_political_party_colour_templates)
col1 <- '#ED2128'
col2 <- '#FFDD00'
col3 <- '#00A6FF'
col4 <- '#FCC224'
col5 <- '#296633'
col6 <- '#A7CF35'
col7 <- '#1572BA'
col8 <- '#005487'
col9 <- '#66CCFF'
col10 <- '#00753A'
col11 <- '#08099F'
col12 <- '#08510A'

transp <-'55'       # transparency level of points

graph <- ggplot(polls)+
  geom_vline(xintercept = as.Date(startdate), color='#aaaaaabb')+       # vertical line (last election)
  geom_vline(xintercept = as.Date(enddate), color='#aaaaaabb')+         # vertical line (next election)
  geom_segment(aes(x=as.Date(startdate), xend=as.Date(enddate), y=5, yend=5), color='#666666bb', linetype='dashed')+      # horizontal line (election threshold 5%)
  # add poll points
  geom_point(aes_string(x='polldate',y=party1),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col1,transp),fill=paste0(col1,transp))+
  geom_point(aes_string(x='polldate',y=party2),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col2,transp),fill=paste0(col2,transp))+
  geom_point(aes_string(x='polldate',y=party3),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col3,transp),fill=paste0(col3,transp))+
  geom_point(aes_string(x='polldate',y=party4),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col4,transp),fill=paste0(col4,transp))+
  geom_point(aes_string(x='polldate',y=party5),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col5,transp),fill=paste0(col5,transp))+
  geom_point(aes_string(x='polldate',y=party6),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col6,transp),fill=paste0(col6,transp))+
  geom_point(aes_string(x='polldate',y=party7),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col7,transp),fill=paste0(col7,transp))+
  geom_point(aes_string(x='polldate',y=party8),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col8,transp),fill=paste0(col8,transp))+
  geom_point(aes_string(x='polldate',y=party9),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col9,transp),fill=paste0(col9,transp))+
  geom_point(aes_string(x='polldate',y=party10),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col10,transp),fill=paste0(col10,transp))+
  geom_point(aes_string(x='polldate',y=party11),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col11,transp),fill=paste0(col11,transp))+
  geom_point(aes_string(x='polldate',y=party12),size=ifelse(polls$polldate==startdate | polls$polldate==enddate,3,1.5),shape=ifelse(polls$polldate==startdate | polls$polldate==enddate,23,21),color=paste0(col12,transp),fill=paste0(col12,transp))+
  # add trend lines
  # the "span" (smoothing parameter) should be manually changed for individual parties that have less polling data
  geom_smooth(aes_string(x='polldate',y=party1,color=shQuote('col1')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party2,color=shQuote('col2')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party3,color=shQuote('col3')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party4,color=shQuote('col4')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party5,color=shQuote('col5')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party6,color=shQuote('col6')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party7,color=shQuote('col7')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party8,color=shQuote('col8')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party9,color=shQuote('col9')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party10,color=shQuote('col10')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party11,color=shQuote('col11')),span=spansize,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party12,color=shQuote('col12')),span=spansize,se=FALSE)+
  scale_y_continuous(labels = function(x) paste0(x, "%"),limits=c(0,45))+    # add %, manual limits on y-axis
  scale_x_date(limits = as.Date(c(startdate,enddate)), date_minor_breaks = "1 months", date_breaks = "3 months", date_labels = "%b %Y")+    # grid: 1 month, labels: 3 months
  labs(x = "", y = "")+
  scale_color_manual(name="",
                     breaks = c('col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12'),
                     labels = c(party1,party2,party3,party4,party5,party6,party7,party8,party9,party10,party11,party12),
                     values = c('col1'=col1,'col2'=col2,'col3'=col3,'col4'=col4,'col5'=col5,'col6'=col6,'col7'=col7,'col8'=col8,'col9'=col9,'col10'=col10,'col11'=col11,'col12'=col12))+
  # legend appearance
  theme(
    axis.text.x = element_text(size = 11),
    axis.text.y = element_text(size = 12),
    axis.title.y = element_text(size = 16),
    legend.position="right",
    legend.key.width=unit(24, "pt"),
    legend.key.height=unit(24, "pt"),
    legend.text = element_text(size=16, margin = margin(b = 5, t = 5, unit = "pt")))

graph + theme()

ggsave(file="polls.svg", plot=graph, width=18, height=10)

# workaround since svglite doesn't properly work in Wikipedia
aaa=readLines("polls.svg",-1)
bbb <- gsub(".svglite ", "", aaa)
writeLines(bbb,"polls.svg")
CAT.csv
polldate,PSD,PNL,USR,AUR,UDMR,PMP,PRO,ALDE,PPU,PER,APP,FD
2020-12-06,28.90,25.18,15.37,9.08,5.74,4.82,4.09,,1.12,1.12,,
2020-12-06,29.32,25.58,15.86,9.17,5.89,4.93,4.13,,1.33,1.33,,
2021-11-24,40,17,11,15,5,4,1,1,4,,,
2021-11-22,38,18,11,14,5,4,3,1,3,,,
2021-10-30,39,19,11,12,5,5,3,,4,,,
2021-10-26,40,17,13,14,5,4,2,1,4,,,
2021-10-25,35.5,21.9,12.4,14.2,5,2.9,3.2,,0.5,,1.7,
2021-10-21,34.5,16,15,17,5,4.5,1,,2,1,4,
2021-10-20,39,21,11,13,5,,,,,,,
2021-10-17,36.7,19.8,16.4,15.3,3,2.1,3,,,,,
2021-10-15,32,20,13,21,6,,,,,,,
2021-09-29,28,17,18,17.5,5,5.5,4,1,,,3,
2021-09-28,31.6,25.9,15,17,4.6,2.5,2.3,,,,1.2,
2021-09-27,35.4,21.9,9.8,17.1,,2.9,4.4,,,,,
2021-09-21,37,20,13,14,5,4,1,1,4,,,
2021-09-10,36,19,11,14,5,5,3,2,4,,,
2021-09-05,35,20,11,12,5,5,3,3,4,,,
2021-08-24,35,21,14,15,5,5,2,,1,,,
2021-08-20,34,20,12,11,5,5,3,3,4,,,
2021-08-19,35,27,14,14,5,2,2,1,,,,
2021-07-26,38.1,15.1,11.1,15,5.1,,,,,,,
2021-07-19,34,23,13,15,5,,,,,,,
2021-07-15,31,27,15,10,7,2,3,,,2,,
2021-06-24,22.9,25,15,18,5.1,,2,2.9,,,,
2021-06-18,34,22,14,12,4,5,2,3,2,,,
2021-06-15,30.2,26.6,13.2,14.2,,2.8,4.3,,,,,
2021-05-18,36,22,15,11,6,2,5,0,1,1,,
2021-05-18,36,28,11,14,3,,3,,,1,,
2021-05-08,36,23,14,15,5,2,2,,1,1,,
2021-05-07,22.1,23.5,13.6,15.5,8.6,4.6,4.1,,,,,
2021-04-17,33,21,16,12,4,5,3,,4,,,
2021-04-11,28.9,22.3,22.5,10,4,4.2,2.9,,,,,
2021-03-28,35,26,17,12,4,3,2,,,,,
2021-02-26,34,25,16,9,4,3,2,,3,,,
2021-02-14,33,25,20,8,4,4,4,2,,3,,
2021-02-11,28,27,14,16,6,4,1,,,,,
2021-01-17,34,24,16,14,5,3,1,,,,,
2021-01-15,34,26,16,12,5,3,2,,,,,
2020-12-21,35,26,14,15,4,2,2,,,,,
2020-12-20,35,26,15,14,5,2,1,,,,,
2021-11-13,35,8,12,20,5.5,4.5,1.5,0.5,1.5,0.5,4,5
2021-11-12,30.5,3,23,12,5,6.5,5.5,1,2.5,,2.5,7.5
2021-10-21,34,9,15,17,5,4,1,0.5,2,1,4,7
2021-10-17,30,3,17.5,17,4,6,5,1.5,,,3.5,11.5

Date
Source Own work
Author PLATEL

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.

File history

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

Date/TimeThumbnailDimensionsUserComment
current12:57, 7 December 2023Thumbnail for version as of 12:57, 7 December 20231,620 × 900 (180 KB)PLATEL (talk | contribs)upd
16:33, 22 July 2023Thumbnail for version as of 16:33, 22 July 20231,620 × 900 (157 KB)PLATEL (talk | contribs)upd
04:39, 9 March 2023Thumbnail for version as of 04:39, 9 March 20231,620 × 900 (151 KB)PLATEL (talk | contribs)upd
19:00, 4 February 2023Thumbnail for version as of 19:00, 4 February 20231,620 × 900 (143 KB)PLATEL (talk | contribs)usr color
18:47, 4 February 2023Thumbnail for version as of 18:47, 4 February 20231,620 × 900 (143 KB)PLATEL (talk | contribs)upd
10:05, 29 November 2022Thumbnail for version as of 10:05, 29 November 20221,620 × 900 (139 KB)PLATEL (talk | contribs)upd
20:21, 17 July 2022Thumbnail for version as of 20:21, 17 July 20221,620 × 900 (126 KB)PLATEL (talk | contribs)upd
22:09, 28 January 2022Thumbnail for version as of 22:09, 28 January 20221,620 × 900 (117 KB)PLATEL (talk | contribs)upd
03:57, 16 December 2021Thumbnail for version as of 03:57, 16 December 20211,620 × 900 (110 KB)PLATEL (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

File usage on other wikis

Metadata