-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathchapas-impeachment.R
135 lines (114 loc) · 5.36 KB
/
chapas-impeachment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Comparação das chapas do governo e
# oposição para formar a chapa especial de
# análise do impeachment.
library(ggplot2)
library(reshape2)
require(cluster)
require(ade4)
require(scales)
require(FactoMineR)
library(dplyr)
source("R/camara-lib.R")
votos_por_deputado <- recuperar_votos_por_deputado(arquivo.votos = "dados/votacoes.csv",corrigir.migracoes = TRUE)
conselho.etica <- read.table("dados/conselho-de-etica.csv", header=TRUE, quote="\"")
chapas <- read.csv("dados/chapas-impeachment.csv", header=TRUE)
deputados <- read.delim("dados/deputados/deputados.csv")
chapas$chapa <- chapas$comissão
chapas$comissão <- NULL
indicados <- filter(chapas, chapa != "")
indicados$chapa <- droplevels(indicados$chapa)
indicados <- within(indicados,
partido <- factor(partido,
levels = names(sort(table(partido), decreasing = F)),
ordered = TRUE))
# Barplot das composições das chapas.
p <- ggplot() +
geom_bar(data = indicados,
aes(x = partido, y = ..count.. * 0)) +
geom_bar(data = filter(indicados, chapa == "oposição"),
aes(x = partido, fill = chapa)) +
geom_bar(data = filter(indicados, chapa == "governista"),
aes(x = partido, fill = chapa, y = ..count..*(-1))) +
scale_y_continuous(breaks=seq(-10,10,5),labels=abs(seq(-10,10,5))) +
ylab("Quantos deputados") + scale_fill_brewer(palette = "Set2") +
coord_flip() + theme_bw() + theme(panel.border = element_blank())
p
png("plot/impeachment/chapas-impeachment.png",
width = 800, height = 550)
p
dev.off()
# No mapa:
mca1 = MCA(votos_por_deputado,
ncp = 2, # Default is 5
graph = FALSE,
quali.sup = c(1:4),
na.method = "Average") # NA or Average
# data frame with observation coordinates
mca1_obs_df = data.frame(mca1$ind$coord,
nome = votos_por_deputado$nome,
partido = votos_por_deputado$partido,
uf = votos_por_deputado$uf,
id_dep = votos_por_deputado$id_dep)
# To plot
mca1_obs_df$id_dep <- as.integer(as.character(mca1_obs_df$id_dep))
mca1_obs_df$destaque_partido = factor(ifelse(mca1_obs_df$partido %in%
c("pmdb", "psdb", "pt", "psol"),
as.character(mca1_obs_df$partido),
"outros"))
mca1_obs_df <- left_join(mca1_obs_df, select(indicados, ideCadastro, chapa), by = c("id_dep" = "ideCadastro"))
p <- plotMCAstains(mca1_obs_df, alfa = 0.1)
# Referência geral
png("plot/visao-geral-pontos.png", width = 800, height = 600)
p + geom_point(aes(colour = destaque_partido), size = 7) +
scale_colour_manual(values = c(alpha("grey70", .05),
alpha("darkred", .6),
alpha("#0066CC", .6),
alpha("#E69F00", .6),
alpha("#FF3300", .6)),
guide = guide_legend(title = "partido",
override.aes = list(alpha = 1, size = 7)))
dev.off()
# Chapa governista, sem nomes
c1 <- geom_point(data = filter(mca1_obs_df, chapa == "governista"),
aes(x = Dim.1, y = Dim.2, label = nome),
colour = "red", alpha = 0.5, size = 6)
png("plot/impeachment/chapa-governista-pontos.png", width = 800, height = 600)
p + c1
dev.off()
png("plot/impeachment/chapa-governista-pontos-e-nomes.png", width = 800, height = 600)
p + c1 + geom_text(data = filter(mca1_obs_df, chapa == "governista"),
aes(x = Dim.1, y = Dim.2, label = paste(nome, "-", toupper(partido))),
check_overlap = TRUE,
colour = "red", alpha = 0.5, size = 3.5, hjust = -.15)
dev.off()
c2 <- geom_point(data = filter(mca1_obs_df, chapa == "oposição"),
aes(x = Dim.1, y = Dim.2, label = nome),
colour = "darkcyan", alpha = 0.5, size = 6)
png("plot/impeachment/chapa-oposicao-pontos.png", width = 800, height = 600)
p + c2
dev.off()
png("plot/impeachment/chapas-as-duas-pontos.png", width = 800, height = 600)
p + c1 + c2
dev.off()
png("plot/impeachment/chapas-as-duas-pontos-e-manchas.png", width = 800, height = 600)
p + c1 + c2 + stat_density2d(aes(fill = chapa, #colour = chapa,
alpha = ..level..),
geom = "polygon") +
scale_alpha(range = c(.1, .3), guide = "none")
dev.off()
png("plot/impeachment/chapa-oposicao-pontos-e-nomes.png", width = 800, height = 600)
p + c2 + geom_text(data = filter(mca1_obs_df, chapa == "oposição"),
aes(x = Dim.1, y = Dim.2, label = paste(nome, "-", toupper(partido))),
check_overlap = TRUE,
colour = "darkcyan", alpha = 0.5, size = 3.5, hjust = 1.1)
dev.off()
p + stat_density2d(aes(fill = destaque_partido, colour = destaque_partido,
alpha = ..level..,
size = ..level..),
geom = "polygon") +
scale_alpha(range = c(0, 1/2), guide = "none") +
scale_size(range = c(0, 6/2), guide = "none")
p + stat_density2d(aes(fill = chapa, #colour = chapa,
alpha = ..level..),
geom = "polygon") +
scale_alpha(range = c(0, 1/2), guide = "none")