R语言会员费用分析可视化报告 附代码数据文档格式.docx
《R语言会员费用分析可视化报告 附代码数据文档格式.docx》由会员分享,可在线阅读,更多相关《R语言会员费用分析可视化报告 附代码数据文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
##filter,lag
base'
##intersect,setdiff,setequal,union
library(ggplot2)
dadosCEAP<
-read.csv("
data/dadosCEAP.csv"
)
现在我们要对列值“Glosa”中的数据进行一个小的修改,用小数点替换逗号,这样就可以在R中被接受为一个数字变量。
我们也将删除这些帐号的负值,价值-1000雷亚尔,议员应该有相当的成本,即+1000雷亚尔,但没有观察到,因此,除了第5号以外,我们将忽视所有问题的负面价值。
dadosCEAP$valorGlosa<
-as.numeric(sub("
"
"
."
dadosCEAP$valorGlosa,fixed=TRUE))#完整数据
gastosCEAP<
-subset(dadosCEAP,valorDocumento>
0)#没有负值的数据
∙哪些方面充分利用了CEAP?
哪些方面使用最少?
在R$中的相同问题conisderando值。
为了回答第一个这些问题,我们将对每个政党与CEAP的支出数量进行整理和总结,之后我们将显示一个条形图,以便更好地呈现这个摘要。
条形图将允许我们可视化使用CEAP的各方越来越多。
usoPorPartido=gastosCEAP%>
%
group_by(sgPartido)%>
summarise(usoPartido=length(sgPartido))%>
arrange(desc(usoPartido))
ggplot(data=usoPorPartido,aes(x=reorder(sgPartido,-as.numeric(usoPartido)),
y=as.factor(usoPartido),fill=as.factor(sgPartido)))+
geom_bar(stat="
identity"
binwidth=NULL,na.rm=TRUE)+
labs(fill="
Partidos"
title="
QuantidadedegastosCEAPporpartido"
x="
Partido"
y="
Nú
merodegastosporPartido"
)+
theme(axis.text.x=element_text(angle=90,hjust=1))
只选择最多使用CEAP的6方,我们可以更清楚地验证上一个问题的答案,然后我们将显示最多使用CEAP的前6名聚会。
top6Ceap<
-head(usoPorPartido)
ggplot(top6Ceap,aes(x=reorder(sgPartido,-as.numeric(usoPartido)),y=as.factor(usoPartido),fill=sgPartido))+
Top6-PartidosquemaisusamoCEAP"
使用CEAP的各方分别是PT,PMDB,PSDB,PP,PR和PSB。
为了回答第一个问题的第二部分,我们将使用类似的过程,但这次我们将根据各方费用的总和来总结数据。
valorPorPartido<
-gastosCEAP%>
summarise(gastosTotais=sum(valorDocumento,na.rm=TRUE))%>
arrange(desc(gastosTotais))
ggplot(valorPorPartido,aes(x=reorder(sgPartido,-as.double(gastosTotais)),
y=as.factor(gastosTotais),fill=as.factor(sgPartido)))+
GastostotaisporpartidoemR$"
GastoporPartido(R$)"
为了更加密切地了解消费最多的各方,我们还将选择与CEAP最多的6个聚会,并展示与CEAP最多的聚会的前6名。
top6GastoCeap<
-head(valorPorPartido)
ggplot(top6GastoCeap,aes(x=reorder(sgPartido,-as.double(gastosTotais)),y=as.factor(gastosTotais),fill=as.factor(sgPartido)))+
Top6-PartidosquemaisgastamcomCEAP"
PodemosverqueospartidosquemaisgastamcomCEAPsã
o,respectivamente,PMDB,PT,PP,PSDB,PRePSD.
∙2QuaisostiposdedespesamaiscomunsnousodaCEAP?
MesmaperguntaconsiderandovaloresemR$.
Pararesponderaprimeirapartedasegundapergunta,agruparemososdadosportipodedespesaesumarizaremosdeacordocomaquantidadedecadaumdosdiferentestiposdedespesas.Selecionaremosapenasas6despesasmaiscomuns.
despesasComuns=head(gastosCEAP%>
group_by(tipoDespesa)%>
summarise(qtd=length(tipoDespesa),na.rm=TRUE)%>
arrange(desc(qtd)))
Tivemosumproblemacomacó
dificaç
ã
odosdadosdoarquivoCSVoriginalnaplataformaWindows,entã
o,tivemosquefazeralgunsajustesparamelhorvizualizaç
odosdados.
despesasComuns$tipoDespesa<
-as.factor(sub("
EmissÃ
£
oBilheteAÃ
©
reo"
BILHETESAEREOS"
despesasComuns$tipoDespesa,fixed=TRUE))
COMBUSTÃ
?
VEISELUBRIFICANTES."
COMBUSTIVEIS"
FORNECIMENTODEALIMENTAÃ
‡Ã
ƒODOPARLAMENTAR"
ALIMENTACAOO"
SERVIÃ
‡ODETÃ
XI,PEDÃ
GIOEESTACIONAMENTO"
TRANSPORTE"
‡OSPOSTAIS"
SERVICOSPOSTAIS"
Apó
sessareorganizaç
odosdados,exibiremosumgrá
ficocontendoostiposdedespesamaiscomunsdeCEAPdosparlamentares.
ggplot(despesasComuns,aes(x=reorder(tipoDespesa,-qtd),y=as.factor(qtd),fill=as.factor(tipoDespesa)))+
na.rm=TRUE)+
TipodeDespesa"
Tiposdegastosmaiscomuns."
TipodeDeDespesa"
Quantidade"
theme(axis.text.x=element_blank())
PodemosperceberqueasdespesasmascomunsdoCEAPsã
o,respectivamente,bilhetesaé
reos,combustiveis,telefonia,serviç
ospostais,alimentaç
oetransporte
Pararesponderasegundapartedapergunta,utilzaremosumprocessoaná
logoefaremososmesmosajustespormotivosdecó
o,adiferenç
aé
queagoraconsideraremososomató
ridosdosvaloresdasatividadesaoinvé
zdaquantid