EDA on Greek Parliament

Let’s explore the MPs that got elected the most over the years (1981-2019).

R
EDA
Author

stesiam

Published

October 10, 2022

Introduction

And here we go…

This is the first notebook on my website and I’d like to be a little special. I didn’t want to just take a ready-made dataset and apply a machine learning technique (I will do this in the next articles). So, I decided to make my own with the help of hellenic’s parliament website.

The Greek political scene has particularly preoccupied global public opinion in recent years, due to the Greek economic crisis. A part of it was spent on the reasons that caused it. The causes of the Greek crisis are many and a point of contention to this day. In this article we will deal essentially with one of the points of criticism. The election of the same persons.

With this notebook I will try to analyze whether this claim is valid by counting how many times someone has been elected to the Greek parliament. In addition, I will study the obsession with the same persons at the party level, but also at the local level (constituencies).

Prerequisites

Import Libraries

First and foremost, we have to load our libraries.

Show the code
# General purpose R libraries
library(tidyverse)
library(kableExtra)
library(reactable)


# Graphs
library(ggplot2)
library(ggpol) 
library(ggtext)

# Other settings
options(digits=2) # print only 2 decimals

Import dataset

After loading R libraries, then I will load my data.

Show the code
parliament <- read_csv("data/greek_parliament.csv")

Preview Dataset

Show the code
preview_dataset = head(parliament, 10)
kbl(preview_dataset, 
    align = 'c',
    booktabs = T,
    centering = T,
    valign = T) %>%
  kable_paper() %>%
  scroll_box(width = "600px", height = "250px")
Table 1: Preview Dataset (first 6 rows)
FullName Party Constituency Term
Agorastis Vasileios PA.SO.K. (Panhellenic Socialist Movement) Larissa 3
Akrita Sylva - Kaiti PA.SO.K. (Panhellenic Socialist Movement) Athens B 3
Akritidis Nikolaos PA.SO.K. (Panhellenic Socialist Movement) Thessaloniki A 3
Akrivakis Alexandros PA.SO.K. (Panhellenic Socialist Movement) Viotia 3
Alevras Ioannis PA.SO.K. (Panhellenic Socialist Movement) Athens A 3
Alexandris Efstathios (Stathis) PA.SO.K. (Panhellenic Socialist Movement) Athens B 3
Alexiadis Konstantinos PA.SO.K. (Panhellenic Socialist Movement) Trikala 3
Alexiou Thomas NEA DIMOKRATIA Xanthi 3
Allamanis Stylianos NEA DIMOKRATIA Karditsa 3
Amanatidis Konstantinos PA.SO.K. (Panhellenic Socialist Movement) Thessaloniki B 3

Structure of Dataset

Variable Property Description
Full Name qualitative
(nominal)
Surname and name of the member of parliament
Party qualitative
(nominal)
The party on which the MP got elected
Constituency qualitative
(nominal)
MP got elected on this area
Term qualitative
(ordinal)
Plenum term

Thus, my sample has 4 variables, of which 0 are quantitative and 4 are quantitative properties, of which 3 are nominal and the rest one (Term) is ordinal.

Recoding variables

Party names can vary from short to lengthy ones. The last ones are a problem for our analysis because their names can not fit to our visualisations. The table below is showing all the parties that have ever participated in parliament. Is is apparent that some parties have really long names.

Show the code
data.frame(
  Party = unique(parliament$Party),
  Length = str_length(unique(parliament$Party))
) %>%
  arrange(-Length) %>%
  reactable(
    defaultPageSize = 5
  )

In our case the parties with the longest name is AN.EL. and Democratic Coalition with 81 and 70 characters, respectively. On the contrary, the shortest party name is POL.A. with 6 characters.

Show the code
## Recoding parliament$Party
parliament$Party[parliament$Party == "ANEXARTITOI DIMOKRATIKOI VOULEFTES"] <- "ADP"
parliament$Party[parliament$Party == "ANEXARTITOI ELLINES (Independent Hellenes)"] <- "ANEL"
parliament$Party[parliament$Party == "ANEXARTITOI ELLINES (Independent Hellenes) National Patriotic Democratic Alliance"]<- "ANEL"
parliament$Party[parliament$Party == "Coalition of the Left and Progress"] <- "SYRIZA"
parliament$Party[parliament$Party == "Communist Party of Greece (Interior)"] <- "KKE (interior)"
parliament$Party[parliament$Party == "DEMOCRATIC COALITION (Panhellenic Socialist Movement Democratic Left )"] <- "PASOK"
parliament$Party[parliament$Party == "DHM.AR (Democratic Left)"] <- "DHMAR"
parliament$Party[parliament$Party == "DI.ANA."] <- "DIANA"
parliament$Party[parliament$Party == "DI.K.KI."] <- "DIKKI"
parliament$Party[parliament$Party == "INDEPENDENT"] <- "INDEPENDENT"
parliament$Party[parliament$Party == "KOMMOUNISTIKO KOMMA ELLADAS"] <- "KKE"
parliament$Party[parliament$Party == "LA.O.S."] <- "LAOS"
parliament$Party[parliament$Party == "LAIKI ENOTITA"] <- "LAE"
parliament$Party[parliament$Party == "LAIKOS SYNDESMOS - CHRYSI AVGI (People’s Association – Golden Dawn)"] <- "XA"
parliament$Party[parliament$Party == "NEA DIMOKRATIA"] <- "ND"
parliament$Party[parliament$Party == "PA.SO.K. (Panhellenic Socialist Movement)"] <- "PASOK"
parliament$Party[parliament$Party == "POL.A."] <- "POLA"
parliament$Party[parliament$Party == "SYNASPISMOS RIZOSPASTIKIS ARISTERAS"] <- "SYRIZA"
parliament$Party[parliament$Party == "TO POTAMI (The River)"] <- "POTAMI"
parliament$Party[parliament$Party == "ΟΟ.ΕΟ."] <- "ΟΟ.ΕΟ"

Setting colors

A few days after, I decided that there should be a consistency in the choice of colors. That’s the reason of this section. Thus, I will assign a dedicated hex color code to each party.

Show the code
kke_color = "#FF6666"
nd_color = "#0492c2"
pasok_color = "#95bb72"
syriza_color = "#e27bb1"

Parliament over the years

Now, I will make a short sum-up of the electoral resuts over the years. It is important to share that I made it thanks to this post and ggpol package. As I am planning to do this procedure for many electoral terms, I will convert it as a function.

Arguments like term and custom_title are vital to create reproducible plots for all the terms. Although a main problem is the colors. On the aforementioned post it was about only one term. We knew how many parties we had, so we knew what colors to set and how many. If we try that on many terms (on which the number of parties can vary from 3 to 8) an error will come up which will say “Hey, you have set 3 colors but I see that you have 8 values (parties)”. This was a real obstacle for me. After some tries and misses I came up with the concept of dynamic arguments.

Show the code
make_parliament_plot <- function(term, custom_title, ...){

custom = parliament %>% filter(Term == term) %>% select(Party) %>% table() %>% t() %>% as.data.frame() %>%  `colnames<-`(c("","Party", "Seats"))

colors<-c(...)

custom$legend <- paste0(custom$Party," (", custom$Seats,")")

#draw a parliament diagram 
p<-ggplot(custom) + 
  geom_parliament(aes(seats =Seats, fill =  Party), color = "white") + 
  scale_fill_manual(values = colors , labels = custom$legend) +
  coord_fixed() + 
  theme_void()+
  labs(title  = custom_title,
       caption = "Source: stesiam | stesiam.github.io, 2022")+
  theme(title = element_text(size = 18),
        plot.title = element_text(hjust = 0.5,size = 14,face = 'bold'),
        plot.subtitle = element_text(hjust = 0.5),
        plot.caption = element_text(vjust = -3,hjust = 0.9, size = 8),    
        legend.position = 'bottom',
        legend.direction = "horizontal",
        legend.spacing.y = unit(0.1,"cm"),
        legend.spacing.x = unit(0.1,"cm"),
        legend.key.size = unit(0.8, 'lines'),
        legend.text = element_text(margin = margin(r = 1, unit = 'cm')),
        legend.text.align = 0)+
        guides(fill=guide_legend(nrow=3,byrow=TRUE,reverse = TRUE,title=NULL))

return(p)
}
Note

Note that till this moment I have not figure out how to change the position of the parties in an efficient way (in a function) that will somehow represent their potitical view. The next visualizations of the parliament are exclusively about how many MPs got elected by each party.

Show the code
make_parliament_plot(3, "Greek Parliament (1981-1985)", "#f72100","#10459c","#26d43a")
Warning: The `legend.text.align` argument of `theme()` is deprecated as of ggplot2
3.5.0.
ℹ Please use theme(legend.text = element_text(hjust)) instead.
Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.

Show the code
make_parliament_plot(4, "Greek Parliament (1985-1989)", "#cccccc","#f72100","#900603","#10459c","#26d43a")

Show the code
make_parliament_plot(5, "Greek Parliament (Jun,1989 - Nov,1989)", "#d6b85a","#cccccc","#10459c","#26d43a","#FFC0CB")

Show the code
make_parliament_plot(6, "Greek Parliament (Nov,1989 - Apr,1990)","#cccccc","#10459c","#26d43a","#FFC0CB","#cefad0")

Show the code
make_parliament_plot(7, "Greek Parliament (Apr,1990 - Oct,1993)", "#cccccc", "#f72100", "#10459c","#26d43a","#FFC0CB","#cefad0")

Show the code
make_parliament_plot(8, "Greek Parliament (Apr,1990 - Oct,1993)", "#f72100", "#10459c","#26d43a","#3944bc")

Show the code
make_parliament_plot(9, "Greek Parliament (Oct,1993 - Aug,1996)", "#FFA500", "#cccccc","#10459c","#3944bc","#26d43a", "#FFC0CB")

Show the code
make_parliament_plot(10, "Greek Parliament (2000 - 2004)", "#cccccc","#f72100","#3944bc","#26d43a", "#FFC0CB")

Show the code
make_parliament_plot(11, "Greek Parliament (2004 - 2007)", "#cccccc","#f72100","#3944bc","#26d43a", "#FFC0CB")

Show the code
make_parliament_plot(12, "Greek Parliament (2007 - 2009)", "#f72100","#1E3F66","#3944bc","#26d43a", "#FFC0CB")

Show the code
make_parliament_plot(13, "Greek Parliament (2009 - May,2012)", "#bcd2e8", "#680c07","#000000","#f72100","#1E3F66","#3944bc","#26d43a", "#FFC0CB")

Show the code
make_parliament_plot(14, "Greek Parliament (May,2012 - Jun,2012)", "#bcd2e8", "#680c07","#f72100","#3944bc","#26d43a", "#FFC0CB", "#000000")

Show the code
make_parliament_plot(15, "Greek Parliament (Jun,2012 - Jan,2015)", "#65350f", "#bcd2e8", "#680c07","#cccccc","#f72100","#3944bc", "#26d43a", "#FFC0CB", "#000000")

Show the code
make_parliament_plot(16, "Greek Parliament (Jan, 2015 - Aug,2015)", "#bcd2e8", "#f72100","#7a1712","#3944bc","#26d43a", "#00ccd3", "#FFC0CB", "#000000")

Warning

As you can see on the next plot there are many MPs that are classified as independent (according to Hellenic’s Parliament website). Many of them are members of parties “ANEL” and “Enosi Kentroon”. However, a large wave of departures from the parties led to not fulfilling the conditions to be considered as parliamentary parties. For that reason members of these parties (that did not left) are considered independent.

Show the code
make_parliament_plot(17, "Greek Parliament (Sep,2015 - 2019)", "#cccccc", "#f72100","#3944bc","#26d43a","#00ccd3", "#FFC0CB","#000000")

Most elected members of parliament

Show the code
#total_times_elected_freqs <- function(input_constituency, min_times_elected){
total_times_elected_freqs_df = parliament %>%  count(FullName, Party) %>% filter(n >= 9) %>% as.data.frame()
  
#df = table(parliament$FullName)%>% sort(decreasing = T) %>% as.data.frame() %>% filter(Freq>=11)

ggplot(data = total_times_elected_freqs_df, aes(x = reorder(FullName, n), y = n, fill = Party ))+
  geom_bar(stat = "identity",width = 0.88) +
  geom_text(aes(label=n), hjust = 1.5, vjust=0.5, color="white", size=4)+
  theme_minimal() +
  scale_fill_manual(values = c("KKE" = kke_color,"ND" = nd_color, "PASOK" = pasok_color, "SYRIZA" = syriza_color)) +
  labs(title = "Most elected MPs on Greek Parliament (1981 - 2019) <br>
       <span style = 'font-size:10pt'> A list that shows the most elected members of parliament (elected 11 times or more). <br> The following ones are members of <span style = 'color:blue;'>ND</span>,  or <span style = 'color:darkgreen;'>PASOK</span></span>.",
       caption = "Source: **stesiam** | stesiam.github.io, 2022",
       x = "Times elected",
       y = "Members of Parliament") +
    theme(
    plot.title.position = "plot",
    plot.title = element_textbox_simple(
      size = 14,
      lineheight = 1,
      padding = margin(5.5, 5.5, 5.5, 5.5),
      margin = margin(0, 0, 5.5, 0),
      fill = "cornsilk"
    ))+
  coord_flip()

Most elected MPs

Most elected members by party

So far we have seen the most elected members of Greek parliament for the period 1981-2019. Ιt would be particularly interesting to study the same feature by party. However, finding the most elected member per party can be challenging on parties with relatively low representation on Greek parliament. That is the reason for choosing only some of those.

Concerning the implementation part, I see that I will make some visualizations with minimum changes (e.g., filter dataset based on party, change color, etc.) so, the creation of a function is justified. That way, I will not repeat same code, following one of the principles of programming (DRY - Don’t Repeat Yourself). On the following function we can see that I set 3 variables :

  • Party : I have to specify which data to filter
  • color : In order to customize color of my barplots to be similar to each party’s color
  • times_elected_min : A argument that I added up later. The problem with its absence is that I have to deal with parties that elect for example 150 MPs and some others just 10. If I set a universal number of elections to visualize I will have diagrams with many problems. Let’s suppose that I set a big value (e.g., 10). Then I would visualize my data for ND and PASOK, although parties with relatively low number of MPs would have only one or noone to show (KKE & SYRIZA, respectively). On the other hand if I set a low value I create a new problem as there will be many MPs of and it creates the need to edit many more things (like width of bars). An argument like times_elected_min can adapt the specific characteristics of each party.
Show the code
party_plot <- function(party, party_color, times_elected_min){
  party_df = parliament %>% filter(Party == party) %>%
  select(FullName) %>% table() %>% sort(decreasing = TRUE) %>% as.data.frame() %>% filter(Freq >= times_elected_min) %>% `colnames<-`(c("Full_Name", "Freq"))
  
ggplot(data = party_df, aes(x = reorder(Full_Name , Freq), y = Freq))+
  geom_bar(stat = "identity",width = 0.88, fill = party_color) +
  geom_text(aes(label=Freq), hjust = 1.5, vjust=0.5, color="white", size=4)+
  theme_minimal() +
   labs(title = "Most elected MPs",
       subtitle = "",
       caption = "Source: stesiam | stesiam.github.io, 2022",
       x = "Times elected",
       y = "Members of Parliament") +
  coord_flip()
}

The visualizations are presented in alphabetical order.

KKE

Show the code
party_plot("KKE", "#FF6666", times_elected_min = 5)

ND

Show the code
party_plot("ND", "#0492c2", times_elected_min = 10)

PASOK

Show the code
party_plot("PASOK", "#95bb72", times_elected_min = 10)

SYRIZA

Show the code
party_plot("SYRIZA", "#e27bb1", times_elected_min = 5)

Most elected members based per constituency

So far we have seen :

  • the composition of Greek Parliament
  • the most elected MPs on national level and
  • the most elected MPs on party level

The last part of my analysis will investigate the most popular MPs on local level (per profecture).

Obviously, the same logic applies to party charts (same processes with minor changes), so the use of a function is almost mandatory (over fifty -50- cases !).

On my previous workflow I used table() function in order to take frequencies. That’s one easy way to go. Although I didn’t figured out to add characteristics from other columns (like party of the MP). Fir that reason I took the decision to use count() instead of table.

Show the code
constituency_freqs <- function(input_constituency, min_times_elected){
cont_df = parliament %>% filter(Constituency == input_constituency) %>%
  count(FullName, Party) %>% filter(n >= min_times_elected) %>% as.data.frame()
  
  ggplot(data = cont_df, aes(x = reorder(FullName, n), y = n, fill = Party ))+
  geom_bar(stat = "identity",width = 0.88) +
  scale_fill_manual(values = c("ANEL" = "#bcd2e8", "INDEPENDENT" = "#cccccc","KKE"=kke_color,"ND" = nd_color, "PASOK" = pasok_color, "SYRIZA" = syriza_color,"XA" = "#000000")) +
  geom_text(aes(label=n), hjust = 1.5, vjust=0.5, color="white", size=4)+
  theme_minimal() +
   labs(title = "Most elected MPs",
       subtitle = "",
       caption = "Source: stesiam | stesiam.github.io, 2022") +
  coord_flip()
}

Now I have frequencies and the party for every MP. That will be useful on my diagrams.

Show the code
#unique(parliament$Constituency) %>% sort()

State

Show the code
constituency_freqs("State", 3)

Attica

Show the code
constituency_freqs("Athens A",5)

Show the code
constituency_freqs("Athens B",7)

Show the code
constituency_freqs("Piraeus A",5)

Show the code
constituency_freqs("Piraeus B",5)

Show the code
constituency_freqs("Of Attica (rest)",5)

Central Greece

Show the code
constituency_freqs("Viotia",5)

Show the code
constituency_freqs("Evrytania",2)

Show the code
constituency_freqs("Fokida",2)

Show the code
constituency_freqs("Fthiotida",3)

Central Macedonia

Show the code
constituency_freqs("Thessaloniki A",6)

Show the code
constituency_freqs("Thessaloniki B",6)

Show the code
constituency_freqs("Kilkis",3)

Show the code
constituency_freqs("Pella",3)

Show the code
constituency_freqs("Pieria",3)

Show the code
constituency_freqs("Serres",3)

Show the code
constituency_freqs("Halkidiki",3)

Crete

Show the code
constituency_freqs("Chania",3)

Show the code
#constituency_freqs("Irakleio",3)
Show the code
constituency_freqs("Lasithi",3)

Show the code
constituency_freqs("Rethymno",3)

Eastern Macedonia and Thrace

Show the code
constituency_freqs("Drama",3)

Show the code
constituency_freqs("Evros",4)

Show the code
constituency_freqs("Kavala",3)

Show the code
constituency_freqs("Xanthi",3)

Show the code
constituency_freqs("Rodopi",3)

Epirus

Show the code
constituency_freqs("Arta",3)

Show the code
constituency_freqs("Ioannina",4)

Show the code
constituency_freqs("Preveza",3)

Show the code
constituency_freqs("Thesprotia",3)

Ionian Islands

Show the code
constituency_freqs("Corfu",3)

Show the code
constituency_freqs("Kefallonia",3)

Show the code
constituency_freqs("Lefkada",3)

Show the code
constituency_freqs("Zakynthos",3)

North Aegean

Show the code
constituency_freqs("Chios",3)

Show the code
constituency_freqs("Lesvos",3)

Show the code
constituency_freqs("Samos",3)

Peloponnese

Show the code
constituency_freqs("Argolida",3)

Show the code
constituency_freqs("Arcadia",3)

Show the code
constituency_freqs("Korinthia",3)

Show the code
constituency_freqs("Lakonia",3)

Show the code
constituency_freqs("Messinia",3)

South Aegean

Show the code
constituency_freqs("Dodecanese Islands",3)

Show the code
constituency_freqs("Cyclades",3)

Thessaly

Show the code
constituency_freqs("Karditsa",3)

Show the code
constituency_freqs("Larissa",3)

Show the code
constituency_freqs("Magnesia",3)

Show the code
constituency_freqs("Trikala",3)

Western Greece

Show the code
constituency_freqs("Achaia",3)

Show the code
#constituency_freqs("Aitoloakarnania",3)
Show the code
constituency_freqs("Ileia",3)

Western Macedonia

Show the code
constituency_freqs("Florina",3)

Show the code
constituency_freqs("Grevena",3)

Show the code
constituency_freqs("Kastoria",3)

Show the code
constituency_freqs("Kozani",3)

Acknowledgments

References

Lin, G. (2024). Reactable: Interactive data tables for r. Retrieved from https://glin.github.io/reactable/
Müller, K., & Wickham, H. (2023). Tibble: Simple data frames. Retrieved from https://tibble.tidyverse.org/
R Core Team. (2021). R: A language and environment for statistical computing. Vienna, Austria: R Foundation for Statistical Computing. Retrieved from https://www.R-project.org/
Tiedemann, F. (2020). Ggpol: Visualizing social science data with ggplot2. Retrieved from https://github.com/erocoar/ggpol
Wickham, H. (2016). ggplot2: Elegant graphics for data analysis. Springer-Verlag New York. Retrieved from https://ggplot2.tidyverse.org
Wickham, H. (2022a). Forcats: Tools for working with categorical variables (factors). Retrieved from https://forcats.tidyverse.org/
Wickham, H. (2022b). Tidyverse: Easily install and load the tidyverse. Retrieved from https://tidyverse.tidyverse.org
Wickham, H. (2023). Stringr: Simple, consistent wrappers for common string operations. Retrieved from https://stringr.tidyverse.org
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686
Wickham, H., Chang, W., Henry, L., Pedersen, T. L., Takahashi, K., Wilke, C., … van den Brand, T. (2024). ggplot2: Create elegant data visualisations using the grammar of graphics. Retrieved from https://ggplot2.tidyverse.org
Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2023). Dplyr: A grammar of data manipulation. Retrieved from https://dplyr.tidyverse.org
Wickham, H., & Girlich, M. (2022). Tidyr: Tidy messy data. Retrieved from https://tidyr.tidyverse.org
Wickham, H., & Henry, L. (2023). Purrr: Functional programming tools. Retrieved from https://purrr.tidyverse.org/
Wickham, H., Hester, J., & Bryan, J. (2022). Readr: Read rectangular text data. Retrieved from https://readr.tidyverse.org
Wilke, C. O., & Wiernik, B. M. (2022). Ggtext: Improved text rendering support for ggplot2. Retrieved from https://wilkelab.org/ggtext/
Zhu, H. (2021). kableExtra: Construct complex table with kable and pipe syntax. Retrieved from http://haozhu233.github.io/kableExtra/

Citation

BibTeX citation:
@online{2022,
  author = {, stesiam},
  title = {EDA on {Greek} {Parliament}},
  date = {2022-10-10},
  url = {https://www.stesiam.com/english-posts/2022-10-10-EDA-Greek-Parliament/},
  langid = {en}
}
For attribution, please cite this work as:
stesiam. (2022, October 10). EDA on Greek Parliament. Retrieved from https://www.stesiam.com/english-posts/2022-10-10-EDA-Greek-Parliament/