Skip to content

Commit

Permalink
modified gov script
Browse files Browse the repository at this point in the history
  • Loading branch information
filippoweb3 committed Nov 8, 2023
1 parent 9520159 commit a060515
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions Scripts/gov_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ library(dplyr)
library(ggplot2)
library(gridExtra)
library(grid)
library(scales)


refn <- 219
N <- 14165
refn <- 240
N <- 9700
scale <- 1e-3

mydata <- data.frame()

for (i in 1:15){
for (i in 1:6){

id <- seq(0, 14)
id <- seq(0, 5)

mydata <- rbind(mydata, read.csv(paste0("/Users/filippo/Downloads/referenda2_vote-219 (",id[i],").csv")))
mydata <- rbind(mydata, read.csv(paste0("/Users/filippo/Downloads/referenda2_vote-240 (",id[i],").csv")))

}

Expand All @@ -35,8 +37,7 @@ mydata$delegation <- ifelse(!mydata$Delegate.To == "-", "Delegated", "Solo")

sum_tab <- as.data.frame(group_by(mydata, delegation, Voted) %>% summarise(n_acc = length(Account), n_votes = sum(Value), n_eff_votes = sum(Effective.Votes), n_deleg = sum(!Delegate.To == "-")))

sum_tab$n_votes <- round(sum_tab$n_votes/10^6)
sum_tab$n_eff_votes <- round(sum_tab$n_eff_votes/10^6)
sum_tab$n_votes <- round(sum_tab$n_votes)

#table(mydata$Conviction)

Expand All @@ -51,25 +52,21 @@ p0 <- ggplot(sum_tab, aes(y=n_acc, x=delegation, fill = Voted)) +
p1 <- ggplot(sum_tab, aes(y=n_eff_votes, x = delegation, fill = Voted)) +
geom_bar(stat = "identity") +
theme(legend.position="none") +
scale_y_continuous(labels = label_number(suffix = "K", scale = scale)) +
labs(y = "Votes (Conviction)", x = "") +
scale_fill_manual(values=c("#89CFF0","#50C878","red")) +
scale_y_continuous(breaks = c(1000000, 10000000, max(sum_tab$n_eff_votes)),
labels = c("1M","10M",paste0(round(max(sum_tab$n_eff_votes)),"M"))) +
geom_text(aes(label=replace(n_eff_votes, n_eff_votes == 0, "")), size=3.5, position = position_stack(vjust = 0.5))

p2 <- ggplot(mydata, aes(x=Value, fill=Voted)) +
geom_histogram(position="dodge") +
theme(legend.position="none") +
scale_x_continuous(trans='log10', breaks = c(0.1, 100, 1000, 10000, 100000, 1000000, max(mydata$Value)),
labels = c("0.1","100","1K","10K","100K","1M",paste0(round(max(mydata$Value)/10^6),"M"))) +
scale_x_continuous(trans='none', labels = label_number(suffix = "K", scale = scale)) +
labs(y = "Count", x = "Votes") +
scale_fill_manual(values=c("#89CFF0","#50C878","red"))

p3 <- ggplot(mydata, aes(x=Effective.Votes, fill=Voted)) +
geom_histogram(position="dodge") +
scale_x_continuous(trans='log10',
breaks = c(0.1, 100, 1000, 10000, 100000, 1000000, max(mydata$Effective.Votes)),
labels = c("0.1","100","1K","10K","100K","1M", paste0(round(max(mydata$Effective.Votes)/10^6),"M"))) +
scale_x_continuous(trans='log10', labels = label_number(suffix = "K", scale = scale)) +
theme(legend.position="none") +
labs(y = "Count", x = "Votes (Conviction)") +
scale_fill_manual(values=c("#89CFF0","#50C878","red"))
Expand Down

0 comments on commit a060515

Please sign in to comment.