File:Opinion polling for the 2022 Hungarian parliamentary election by coalitions.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 1,620 × 900 pixels, file size: 84 KB)

Summary

Description
English: Opinion polling for the 2022 Hungarian parliamentary 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.3         # general smoothing parameter for trend line
startdate <- '2020-11-01'   # date of previous election
enddate <- '2022-04-08'     # (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]

# define party colors (taken from https://en.wikipedia.org/wiki/Category:Germany_political_party_colour_templates)
col1 <- '#FF6A00'
col2 <- '#20B2AA'
col3 <- '#808080'
col4 <- '#568203'
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))+
  # 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)+
  scale_y_continuous(labels = function(x) paste0(x, "%"),limits=c(0,62))+    # 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'),
                     labels = c(party1,party2,party3,party4),
                     values = c('col1'=col1,'col2'=col2,'col3'=col3,'col4'=col4))+
  # 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,Fidesz-KDNP,Opposition,MKKP,MHM
2022-03-27,50,46,1,3
2022-03-23,52,41,3,3
2022-03-18,49,46,,
2022-03-19,50,41,2,5
2022-03-21,49,41,3,2
2022-03-11,50,43,3,4
2022-03-05,54,46,,
2022-02-26,49,43,3,4
2022-02-24,48,46,3,3
2022-02-15,50,43,3,3
2022-02-11,54,41,2,3
2022-02-10,49,46,2,3
2022-02-09,49,44,3,4
2022-01-26,51,43,3,3
2022-01-25,47,47,3,3
2022-01-19,49,44,3,4
2022-01-14,43,39,5,3
2022-01-14,48,44,4,4
2022-01-05,50,43,3,3
2021-12-23,54,45,,
2021-12-15,55,43,,
2021-12-14,43,48,3,4
2021-12-11,46,32,4,5
2021-12-13,47,47,2,3
2021-12-07,44,45,6,5
2021-12-13,47,45,3,4
2021-11-30,46,53,0,1
2021-11-23,41,48,4,3
2021-11-24,48,49,2,2
2021-11-11,55,44,,
2021-11-05,48,45,3,3
2021-11-03,56,42,,
2021-10-29,42,51,2,3
2021-10-27,56,42,,
2021-10-21,55,44,,
2021-10-20,56,43,,
2021-10-13,56,42,,
2021-10-09,47,47,3,3
2021-10-06,44,47,5,4
2021-10-06,54,43,,
2021-10-04,44,52,2,1
2021-10-04,44,52,2,1
2021-09-29,54,44,,
2021-09-21,53,45,,
2021-09-20,49,49,,
2021-09-07,49,45,3,3
2021-08-28,45,52,1,1
2021-08-26,50,45,2,2
2021-08-25,52,46,,
2021-08-01,48,44,4,3
2021-07-04,47,45,3,4
2021-06-16,47,50,,
2021-06-09,52,43,2,3
2021-06-08,50,42,4,4
2021-06-08,46,49,2,2
2021-05-21,44,54,1,1
2021-05-17,48,50,,
2021-05-11,53,45,1,1
2021-05-04,46,48,2,4
2021-04-28,51,43,2,3
2021-04-28,48,51,1,1
2021-04-23,46,52,1,1
2021-04-22,48,49,1,1
2021-03-31,44,48,3,4
2021-03-25,45,53,1,1
2021-03-09,53,44,1,1
2021-03-11,54,40,2,3
2021-03-11,46,50,1,3
2021-02-25,45,48,3,3
2021-02-25,45,54,,
2021-02-22,46,51,2,1
2021-02-13,47,50,,
2021-01-26,44,47,4,3
2021-01-20,52,45,1,1
2021-01-21,46,50,2,2
2020-12-16,51,43,3,2
2020-12-15,47,47,2,3
2020-12-15,46,50,2,2
2020-12-08,48,52,,
2020-12-22,56,44,,
2020-11-21,48,50,,
2020-11-25,49,50,,
Date
Source Own work
Author PLATEL

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.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

16 December 2021

image/svg+xml

File history

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

Date/TimeThumbnailDimensionsUserComment
current11:01, 29 November 2022Thumbnail for version as of 11:01, 29 November 20221,620 × 900 (84 KB)PLATELfinal result
20:27, 30 March 2022Thumbnail for version as of 20:27, 30 March 20221,620 × 900 (77 KB)BeimelJusing new polling results to update chart. i did just use the polling results which were summed up at or near 100 percent
23:14, 2 February 2022Thumbnail for version as of 23:14, 2 February 20221,620 × 900 (63 KB)PLATELupdate
01:36, 16 December 2021Thumbnail for version as of 01:36, 16 December 20211,620 × 900 (54 KB)PLATELUploaded own work with UploadWizard
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

Global file usage

The following other wikis use this file:

Metadata