-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathproporcao_bancadas_cluster.Rmd
205 lines (156 loc) · 6.33 KB
/
proporcao_bancadas_cluster.Rmd
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
title: "Proporção Bancadas Cluster"
author: "Rodolfo Viana"
date: "16-12-2015"
output: html_document
---
Mostra a proporção de deputados de cada bancada em cada cluster
```{r}
#Bibliotecas necessárias
library(ggplot2)
library(plyr)
library(dplyr)
library(reshape2)
require(cluster)
require(ade4)
require(scales)
require(FactoMineR)
require(rCharts)
library(plotly)
library(RColorBrewer)
source("R/camara-lib.R")
```
```{r}
caminho_pasta_resultados = "plot/clusters"
votos_por_deputado <- recuperar_votos_por_deputado(arquivo.votos = "votacoes.csv",corrigir.migracoes = TRUE)
mca <- MCA(votos_por_deputado,
ncp = 6, # Default is 5
graph = FALSE,
quali.sup = c(1:4),
na.method = "Average") # NA or Average
mca1_obs_df <- data.frame(mca$ind$coord,
nome = votos_por_deputado$nome,
partido = votos_por_deputado$partido,
uf = votos_por_deputado$uf,
id_dep = votos_por_deputado$id_dep)
mca1_obs_df$id_dep <- as.integer(as.character(mca1_obs_df$id_dep))
hcpc <- clusterizar(mca,3)
clusters <- obter_clusters(hcpc)
mca1_obs_df <- cbind(mca1_obs_df, select(clusters,clust))
mca1_obs_df$clust <- as.factor(mca1_obs_df$clust)
```
```{r}
# Bancadas
bancada.bala <- read.table("/home/viana/Projetos/houseofcunha/data/bancada-bala.csv", header=TRUE, quote="\"")
bancada.humanista <- read.table("/home/viana/Projetos/houseofcunha/data/bancada-humanista.csv", header=TRUE, quote="\"")
bancada.sindical <- read.table("/home/viana/Projetos/houseofcunha/data/bancada-sindical.csv", header=TRUE, quote="\"")
bancada.evangelica <- read.table("/home/viana/Projetos/houseofcunha/data/bancada-evangelica.csv", header=TRUE, quote="\"")
bancada.ruralista <- read.table("/home/viana/Projetos/houseofcunha/data/bancada-ruralista.csv", header=TRUE, quote="\"")
```
```{r}
# Partidos icônicos
mca1_obs_df$destaque_partido = factor(ifelse(mca1_obs_df$partido %in%
c("pmdb", "psdb", "pt", "psol"),
as.character(mca1_obs_df$partido),
"outros"))
# Destaque dos deputados que participam da bancada bala
mca1_obs_df$destaque_bancada_bala <- mca1_obs_df$nome %in% bancada.bala$Bala
# Destaque dos deputados que participam da bancada humanista
mca1_obs_df$destaque_bancada_humanista <- mca1_obs_df$nome %in% bancada.humanista$Humanista
# Bancada Evangelica
mca1_obs_df$destaque_bancada_evangelica <- mca1_obs_df$nome %in% bancada.evangelica$Evangelica
# Bancada Ruralista
mca1_obs_df$destaque_bancada_ruralista <- mca1_obs_df$nome %in% bancada.ruralista$Ruralista
# Bancada Sindical
mca1_obs_df$destaque_bancada_sindical <- mca1_obs_df$nome %in% bancada.sindical$Sindical
```
Plot mostrando a proporção de deputados por clust
```{r}
dep_clust <- as.data.frame(table(mca1_obs_df$clust))
colnames(dep_clust) <- c("clust", "freq")
dep_clust$porcentagem <- (dep_clust$freq / sum(dep_clust$freq)) * 100
p <- ggplot(data = dep_clust, aes(x=reorder(clust, -porcentagem), y = porcentagem)) +
geom_bar(stat="identity") +
theme_classic() +
labs(y='% de Deputados', x='Clust', title = "Deputados por Clust") +
theme(axis.ticks = element_blank())
png("plot/bancadas/deputados_clust.png", width = 800, height = 600)
p
dev.off()
```
Plots das mostrando a proporção das bancadas por clust
```{r}
# Bancada da Bala
p <- plotBancadas(filter(mca1_obs_df, destaque_bancada_bala == TRUE)) +
labs(y='% da bancada', x='Clust', title = "Bancada da Bala")
png("plot/bancadas/bancada_clust_bala.png", width = 800, height = 600)
p
dev.off()
# Bancada dos direitos humanos
p <- plotBancadas(filter(mca1_obs_df, destaque_bancada_humanista == TRUE)) +
labs(y='% da bancada', x='Clust', title = "Bancada dos Direitos Humanos")
png("plot/bancadas/bancada_clust_direitos_humanos.png", width = 800, height = 600)
p
dev.off()
# Bancada Evangelica
p <- plotBancadas(filter(mca1_obs_df, destaque_bancada_evangelica == TRUE)) +
labs(y='% da bancada', x='Clust', title = "Bancada Evangelica")
png("plot/bancadas/bancada_clust_evangelica.png", width = 800, height = 600)
p
dev.off()
# Bancada Ruralista
p <- plotBancadas(filter(mca1_obs_df, destaque_bancada_ruralista == TRUE)) +
labs(y='% da bancada', x='Clust', title = "Bancada Ruralista")
png("plot/bancadas/bancada_clust_ruralista.png", width = 800, height = 600)
p
dev.off()
# Bancada Sindical
p <- plotBancadas(filter(mca1_obs_df, destaque_bancada_sindical == TRUE)) +
labs(y='% da bancada', x='Clust', title = "Bancada Sindical")
png("plot/bancadas/bancada_clust_sindical.png", width = 800, height = 600)
p
dev.off()
```
Plot das bancadas por clust
```{r}
# Bancada da Bala
p <- plotCluster(mca1_obs_df) +
geom_point(data = filter(mca1_obs_df, destaque_bancada_bala == TRUE), size = 9, alpha = 0.2, colour = "Black") +
coord_equal() +
labs(title = "Bancada da Bala")
png("plot/bancadas/bancada_clust_bala_dep.png", width = 800, height = 600)
p
dev.off()
# Bancada dos direitos humanos
p <- plotCluster(mca1_obs_df) +
geom_point(data = filter(mca1_obs_df, destaque_bancada_humanista == TRUE), size = 9, alpha = 0.2, colour = "Black") +
coord_equal() +
labs(title = "Bancada dos Direitos Humanos")
png("plot/bancadas/bancada_clust_direitos_humanos_dep.png", width = 800, height = 600)
p
dev.off()
# Bancada Evangelica
p <- plotCluster(mca1_obs_df) +
geom_point(data = filter(mca1_obs_df, destaque_bancada_evangelica == TRUE), size = 9, alpha = 0.2, colour = "Black") +
coord_equal() +
labs(title = "Bancada Evangelica")
png("plot/bancadas/bancada_clust_evangelica_dep.png", width = 800, height = 600)
p
dev.off()
# Bancada Ruralista
p <- plotCluster(mca1_obs_df) +
geom_point(data = filter(mca1_obs_df, destaque_bancada_ruralista == TRUE), size = 9, alpha = 0.2, colour = "Black") +
coord_equal() +
labs(title = "Bancada Ruralista")
png("plot/bancadas/bancada_clust_ruralista_dep.png", width = 800, height = 600)
p
dev.off()
# Bancada Sindical
p <- plotCluster(mca1_obs_df) +
geom_point(data = filter(mca1_obs_df, destaque_bancada_sindical == TRUE), size = 9, alpha = 0.2, colour = "Black") +
coord_equal() +
labs(title = "Bancada Sindical")
png("plot/bancadas/bancada_clust_sindical_dep.png", width = 800, height = 600)
p
dev.off()
```