library(readr)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
setwd("C:/Users/dimit/Desktop/Projetos/AD2")
dadosCEAP <- read_csv("dadosCEAP.csv")
## Parsed with column specification:
## cols(
## nomeParlamentar = col_character(),
## idCadastro = col_integer(),
## sgUF = col_character(),
## sgPartido = col_character(),
## tipoDespesa = col_character(),
## especDespesa = col_character(),
## fornecedor = col_character(),
## CNPJCPF = col_character(),
## tipoDocumento = col_integer(),
## dataEmissao = col_datetime(format = ""),
## valorDocumento = col_double(),
## valorGlosa = col_integer(),
## valorLíquido = col_double()
## )
limiteMensalCEAP <- read_csv("limiteMensalCEAP.csv")
## Parsed with column specification:
## cols(
## UF = col_character(),
## limite_mensal = col_double()
## )
options(scipen = 4)
agDeputados <- dadosCEAP %>%
group_by(nomeParlamentar, sgUF, sgPartido) %>%
summarise(count = sum(valorLíquido))
select02 <- select(dadosCEAP, nomeParlamentar, sgUF, sgPartido, dataEmissao, valorLíquido)
select02$dataEmissao <- format(select02$dataEmissao, format="%Y-%m")
select02 <- select02 %>%
group_by(nomeParlamentar, sgUF, sgPartido, dataEmissao) %>%
summarise(valorLiqMensal = sum(valorLíquido))
select02 <- na.omit(select02)
limiteSuperior <- data.frame(nome=character(0),sgUF=character(0),sgPartido=character(0))
for (deputadoIdx in 1:nrow(select02)) {
for (limiteIdx in 1:nrow(limiteMensalCEAP)) {
if (select02[deputadoIdx, "sgUF"] == limiteMensalCEAP[limiteIdx, "UF"]){
if (select02[deputadoIdx, "valorLiqMensal"] > limiteMensalCEAP[limiteIdx, "limite_mensal"]){
limiteSuperior <- add_row(limiteSuperior, nome=select02$nomeParlamentar[deputadoIdx], sgUF=select02$sgUF[deputadoIdx], sgPartido=select02$sgPartido[deputadoIdx])
break
}
}
}
}
nUsoIndevido <- nrow(limiteSuperior)
limiteSuperior$count <- ((1/nUsoIndevido) * 100)
aglimiteSuperior <- limiteSuperior %>%
group_by(nome, sgUF, sgPartido) %>%
summarise(count = sum(count))
É interessante não apenas saber sobre o uso por estado ou partido, mas sim saber se está sendo feito o uso incorreto dessa verba de forma incorreta e em quais categorias (estado ou partido) isso acontece mais frequêntemente.
limiteSuperiorUF <- aglimiteSuperior %>%
group_by(sgUF) %>%
summarise(total = sum(count))
limiteSuperiorUF$sgUF <- factor(limiteSuperiorUF$sgUF, levels = limiteSuperiorUF$sgUF[order(limiteSuperiorUF$total)])
limiteSuperiorPartido <- aglimiteSuperior %>%
group_by(sgPartido) %>%
summarise(total = sum(count))
limiteSuperiorPartido$sgPartido <- factor(limiteSuperiorPartido$sgPartido, levels = limiteSuperiorPartido$sgPartido[order(limiteSuperiorPartido$total)])
ggplot(limiteSuperiorUF, aes(y = limiteSuperiorUF$total, x = limiteSuperiorUF$sgUF, fill = as.factor(sgUF))) +
geom_bar(stat="identity") +
labs(title = "Frequência de uso da CEAP incorretamente por estado", x = "Estado", y = "Frequência(%)", fill = "Estado") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(axis.text=element_text(size=8), axis.title=element_text(size=12,face="bold"))
ggplot(limiteSuperiorPartido, aes(y = limiteSuperiorPartido$total, x = limiteSuperiorPartido$sgPartido, fill = as.factor(sgPartido))) +
geom_bar(stat="identity") +
labs(title = "Frequência de uso da CEAP incorretamente por partido", x = "Partido", y = "Frequência(%)", fill = "Partido") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(axis.text=element_text(size=8), axis.title=element_text(size=12,face="bold"))
Analisando deputado a deputado podemos ver que aproximadamente 65% dos deputados fazem o mal uso da CEAP e aproximadamente 35% fazem o bom uso da mesma.
total_deputados <- nrow(agDeputados)
mal_uso_deputados <- nrow(aglimiteSuperior)
bom_uso_deputados <- ((total_deputados - mal_uso_deputados) / total_deputados) * 100
mal_uso_deputados <- ((nrow(aglimiteSuperior)) / total_deputados) * 100
deputados_info <- data.frame(tipo=character(0),total=integer(0))
deputados_info <- add_row(deputados_info, tipo='Usam bem', total=bom_uso_deputados)
deputados_info <- add_row(deputados_info, tipo='Usam mal', total=mal_uso_deputados)
ggplot(deputados_info, aes(y = deputados_info$total, x = deputados_info$tipo)) +
geom_bar(stat="identity") +
labs(title = "Como os deputados usam a Ceap", x = "Tipo do uso", y = "Total(%)") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(axis.text=element_text(size=8), axis.title=element_text(size=12,face="bold")) +
coord_flip()
Analisando todos os usos da CEAP na base de dados podemos ver que aproximadamente 69.5% das vezes em que CEAP foi usada, ela foi utilizada de forma correta e aproximadamente 30.5% de forma incorreta.
uso_total <- nrow(select02)
mal_uso <- (nUsoIndevido / uso_total) * 100
bom_uso <- ((uso_total - nUsoIndevido) / uso_total) * 100
ceap_info <- data.frame(tipo=character(0),total=integer(0))
ceap_info <- add_row(ceap_info, tipo='Bom uso', total=bom_uso)
ceap_info <- add_row(ceap_info, tipo='Mal uso', total=mal_uso)
ggplot(ceap_info, aes(y = ceap_info$total, x = ceap_info$tipo)) +
geom_bar(stat="identity") +
labs(title = "Uso da CEAP pelos deputados em geral", x = "Uso", y = "Total(%)") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(axis.text=element_text(size=8), axis.title=element_text(size=12,face="bold")) +
coord_flip()