Soubor:Opinion polling for the 2021 Moldovan parliamentary election.svg

Obsah stránky není podporován v jiných jazycích.
Z Wikipedie, otevřené encyklopedie

Původní soubor(soubor SVG, nominální rozměr: 1 620 × 720 pixelů, velikost souboru: 115 KB)

Popis

Popis
English: Opinion polling for the 2021 Moldovan 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.2            # general smoothing parameter for trend line
startdate <- '2019-02-24'   # date of previous election
enddate <- '2021-07-11'     # (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]

# define party colors (taken from https://en.wikipedia.org/wiki/Category:Germany_political_party_colour_templates)
col1 <- '#8C0400'
col2 <- '#CE2821'
col3 <- '#E7C300'
col4 <- '#FFDF00'
col5 <- '#631008'
col6 <- '#294D9C'
col7 <- '#5ABA73'
col8 <- '#C61C18'
col9 <- '#003463'

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))+
  # 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=0.7,se=FALSE)+
  geom_smooth(aes_string(x='polldate',y=party3,color=shQuote('col3')),span=0.8,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)+
  scale_y_continuous(labels = function(x) paste0(x, "%"),limits=c(0,56))+    # 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'),
                     labels = c(party1,party2,party3,party4,party5,party6,party7,party8,party9),
                     values = c('col1'=col1,'col2'=col2,'col3'=col3,'col4'=col4,'col5'=col5,'col6'=col6,'col7'=col7,'col8'=col8,'col9'=col9))+
  # 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=8)

# 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,PSRM,BECS,ACUM,PAS,PPPDA,PDM,SOR,PCRM,PN
2021-07-11,,27.17,,52.8,2.33,1.81,5.74,,4.10
2021-07-10,,23.1,,55.8,1.9,1.1,8.1,,4.5
2021-07-10,,24,,55.1,1.8,1.1,8.1,,4.4
2021-07-02,,37.1,,37.4,5.4,1.3,6.8,,5.5
2021-06-27,,32.5,,43.5,3.5,1.7,7.8,,5.9
2021-06-30,,30.5,,50.9,2.5,1,4.7,,5.2
2021-06-20,,36.7,,38.5,4.4,1.4,6.9,,5.2
2021-06-19,,28,,49.8,1.9,1,4.7,,6.3
2021-06-08,,32.5,,50.5,2,0.8,5.1,,5
2021-06-05,,36.1,,36.5,4.4,2.2,7.3,,4.8
2021-05-28,,35.4,,37.6,3.8,2.3,8.7,,4.2
2021-05-28,,35.4,,39.1,3.5,1.2,10.1,,4.9
2021-05-22,,35.8,,37,3.3,2.5,7.6,,4.4
2021-04-20,37.6,,,39.7,3.2,,10,1.8,3.7
2021-03-31,33.9,,,41.3,4.3,1.2,9.2,2.2,4.9
2021-03-23,32.7,,,42.5,2,2.7,7.1,4.8,4.3
2021-03-16,24,,,42,6,3,6,4,8
2021-02-27,32.7,,,43.1,5.2,0.7,10,1.4,3.3
2021-02-20,32.7,,,36,4.2,2.4,9.7,3.9,7.4
2021-02-16,31.8,,,35.4,3.4,5.4,8.9,2.5,9.9
2021-02-14,26.6,,,48.6,2.8,0.8,8.7,3.3,6.2
2021-01-31,32.8,,,38,4.9,0.9,10.8,3.3,5
2021-01-23,33.2,,,33.9,4.4,1.1,12.9,2.9,7.5
2020-12-14,32.8,,,37.4,2,0.5,13.3,3.2,8
2020-11-07,35.7,,,32.1,2,1.9,10,1.7,12.2
2020-11-07,41.5,,,23.1,6,3.3,10.7,2.2,10.4
2020-10-24,41.7,,,33,7.3,0.6,5.5,0.3,9.3
2020-10-24,34.8,,,27.9,4.6,1.5,12.7,1.9,12.6
2020-10-20,40.9,,,22.8,6.8,3.1,11.3,2,10.2
2020-10-20,35,,,29.6,2.7,1,9.7,1.3,16.1
2020-10-17,34,,,31.2,2.6,1.7,6.3,1.8,10.3
2020-10-09,39.9,,,24.5,5.3,3.3,11.9,2.7,9.9
2020-10-08,39.7,,,22.3,6.1,3.8,10.8,2.3,10.4
2020-10-05,35.2,,,28.2,4.8,2.8,11.8,1.9,11.6
2020-09-22,37.6,,,22.5,7.7,4.7,10.4,3,10
2020-09-02,35.5,,,24,2.5,2.1,13,4.8,11
2020-08-27,37.1,,,26.3,4.7,2.1,10.3,4.8,9.8
2020-08-23,29,,,28,5,5,10,5,7
2020-08-20,39.3,,,26.8,4.9,5.2,8.4,4.3,6.9
2020-07-27,30.4,,,22.6,4.4,3.9,13.4,7.2,10.1
2020-07-26,36.9,,,30.5,5.4,5.3,8.5,2.7,4.8
2020-07-24,43.5,,,27.9,4.2,5,6.5,3.6,5.6
2020-07-09,33.9,,,27.8,5.5,3.6,11,7.1,10.1
2020-07-04,35.3,,,30.4,8.3,3.8,9.3,2.2,5.8
2020-06-27,48.7,,,26.9,7,3.9,2.3,2,6.1
2020-06-27,35.7,,,25.6,3.6,4.7,11.6,5.6,7.7
2020-06-23,34,,,33.9,3.8,5.2,7.4,4.9,5.4
2020-05-31,46.3,,,30.9,7.5,3,3.1,1.7,4.6
2020-05-11,29.8,,,29.1,6.1,11.4,2.9,5.3,6.1
2020-05-07,48.6,,,21.9,7.4,8.7,2.1,2.6,4.4
2020-05-04,48.1,,,22.7,6.8,8.2,3.7,3.3,6.8
2020-04-12,41.6,,,21.2,5,7.8,4.5,6.8,2.8
2020-04-04,50.3,,,21.3,9.3,8.7,1.8,3.9,2.1
2020-03-15,43.9,,,27.6,10,4.1,3.3,7.2,1.2
2020-03-07,47.6,,,28.7,6.3,4.7,3.9,2,3.4
2020-02-19,42.1,,,27.9,2,9.3,6,5.4,2.7
2020-02-16,45.1,,,19.7,5.6,11.8,4.2,4.7,3.7
2020-01-23,40.6,,,27.9,4.1,10.7,4.8,3.4,3.5
2020-01-13,44,,,21.4,6.3,10,4.8,5.8,3
2019-12-23,40.3,,,25.5,4.8,10.8,4.2,4.2,3.6
2019-12-14,38.3,,,27,2,13.5,5,6,4.5
2019-12-08,38,,,27,4,13,5,4,4
2019-11-30,48,,,30,6.4,7,1.9,2.6,3
2019-09-22,43.7,,,25.1,4.3,11.4,5.3,4.9,
2019-09-20,42.9,,,22.6,10,9.4,3,3.6,4.5
2019-08-14,41.9,,,27.3,8.7,6.7,4.6,3.7,3
2019-07-28,41.9,,,29.3,8.2,8.1,3,3.4,1.6
2019-06-22,44.7,,34.1,,,7.6,5,3.3,2.3
2019-06-13,39.8,,32.7,,,11.3,6.3,2.8,1.7
2019-05-10,38.4,,23.5,,,23.8,5.8,3.1,1.8
2019-04-05,38.8,,27.1,,,26.8,6.1,2.7,1.3
2019-02-24,31.15,,26.84,,,23.62,8.32,3.75,2.95

Datum
Zdroj Vlastní dílo
Autor PLATEL

Licence

Já, držitel autorských práv k tomuto dílu, ho tímto zveřejňuji za podmínek následující licence:
w:cs:Creative Commons
uveďte autora zachovejte licenci
Dílo smíte:
  • šířit – kopírovat, distribuovat a sdělovat veřejnosti
  • upravovat – pozměňovat, doplňovat, využívat celé nebo částečně v jiných dílech
Za těchto podmínek:
  • uveďte autora – Máte povinnost uvést autorství, poskytnout odkaz na licenci a uvést, pokud jste provedli změny. Toho můžete docílit jakýmkoli rozumným způsobem, avšak ne způsobem naznačujícím, že by poskytovatel licence schvaloval nebo podporoval vás nebo vaše užití díla.
  • zachovejte licenci – Pokud tento materiál jakkoliv upravíte, přepracujete nebo použijete ve svém díle, musíte své příspěvky šířit pod stejnou nebo slučitelnou licencí jako originál.

Popisky

Přidejte jednořádkové vysvětlení, co tento soubor představuje

Položky vyobrazené v tomto souboru

zobrazuje

Historie souboru

Kliknutím na datum a čas se zobrazí tehdejší verze souboru.

Datum a časNáhledRozměryUživatelKomentář
současná21. 12. 2021, 13:30Náhled verze z 21. 12. 2021, 13:301 620 × 720 (115 KB)PLATELUploaded own work with UploadWizard

Tento soubor používá následující stránka:

Globální využití souboru

Metadata