Gerando tabelas usando
os Microdados importados do IMPUMS International
library(tidyverse)
dados<-data%>%
group_by(COUNTRY)%>%
summarise(pop=sum(PERWT))
dados
dados<-data%>%
group_by(COUNTRY,SEX)%>%
summarise(pop=sum(PERWT))
dados
| 152 |
1 |
8607570 |
| 152 |
2 |
8961420 |
| 858 |
1 |
1577700 |
| 858 |
2 |
1706550 |
dados<-data%>%
group_by(COUNTRY,SEX,AGE)%>%
summarise(pop=sum(PERWT))
head(dados)
| 152 |
1 |
0 |
109070 |
| 152 |
1 |
1 |
120890 |
| 152 |
1 |
2 |
121140 |
| 152 |
1 |
3 |
118290 |
| 152 |
1 |
4 |
120370 |
| 152 |
1 |
5 |
122770 |
dados<-data%>%
mutate(grid=if_else(AGE>=90,90,
(trunc(AGE/5)*5)))%>%
group_by(COUNTRY,SEX,grid)%>%
summarise(pop=sum(PERWT))
head(dados)
| 152 |
1 |
0 |
589760 |
| 152 |
1 |
5 |
618970 |
| 152 |
1 |
10 |
583920 |
| 152 |
1 |
15 |
636750 |
| 152 |
1 |
20 |
701180 |
| 152 |
1 |
25 |
744730 |
dados<-data%>%
mutate(grid=if_else(AGE>=90,90,
(trunc(AGE/5)*5)))%>%
group_by(COUNTRY,SEX,grid)%>%
summarise(pop=sum(PERWT))%>%
ungroup()%>%
group_by(COUNTRY)%>%
mutate(poptotal=sum(pop))
head(dados)
| 152 |
1 |
0 |
589760 |
17568990 |
| 152 |
1 |
5 |
618970 |
17568990 |
| 152 |
1 |
10 |
583920 |
17568990 |
| 152 |
1 |
15 |
636750 |
17568990 |
| 152 |
1 |
20 |
701180 |
17568990 |
| 152 |
1 |
25 |
744730 |
17568990 |
dados<-data%>%
mutate(grid=if_else(AGE>=90,90,
(trunc(AGE/5)*5)))%>%
group_by(COUNTRY,SEX,grid)%>%
summarise(pop=sum(PERWT))%>%
ungroup()%>%
group_by(COUNTRY)%>%
mutate(poptotal=sum(pop))%>%
mutate(poprel=if_else(SEX==1,-100*pop/poptotal,100*pop/poptotal))%>%
mutate(grid_f=factor(grid,ordered=T,
levels=seq(0,90,5),
labels =c('0-4','5-9','10-14','15-19', '20-24', '25-29',
'30-34','35-39','40-44','45-49','50-54','55-59',
'60-64','65-69','70-74','75-79','80-84','85-89',
'90+')))
head(dados)
| 152 |
1 |
0 |
589760 |
17568990 |
-3.356824 |
0-4 |
| 152 |
1 |
5 |
618970 |
17568990 |
-3.523082 |
5-9 |
| 152 |
1 |
10 |
583920 |
17568990 |
-3.323583 |
10-14 |
| 152 |
1 |
15 |
636750 |
17568990 |
-3.624284 |
15-19 |
| 152 |
1 |
20 |
701180 |
17568990 |
-3.991009 |
20-24 |
| 152 |
1 |
25 |
744730 |
17568990 |
-4.238889 |
25-29 |
library(scales)
library(hrbrthemes)
th<-theme_ipsum()+
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=1,size=8),
axis.text.y = element_text(angle = 0, vjust = 0.5, hjust=1,size=8))
ggplot(data=dados,aes(x=grid_f,y=poprel,group=SEX,fill=SEX))+
geom_bar(stat='identity')+
coord_flip()+
facet_wrap(~COUNTRY)+
labs(caption = "Fonte: IMPUS International")+
ggtitle('Pirâmide Etária 2020 - Chile e Uruguay')+
scale_y_continuous(name='População (%)',
labels=label_percent(big.mark = '.',decimal.mark = ','),
breaks = seq(-8,8,2),limits=c(-8,8))+
scale_x_discrete(name='Grupo de Idade')+
scale_fill_discrete(name='Sexo')+
th
library(scales)
library(hrbrthemes)
library(haven)
dados<-data%>%
mutate(grid=if_else(AGE>=90,90,
(trunc(AGE/5)*5)))%>%
group_by(COUNTRY,SEX,grid)%>%
summarise(pop=sum(PERWT))%>%
ungroup()%>%
group_by(COUNTRY)%>%
mutate(poptotal=sum(pop))%>%
mutate(poprel=if_else(SEX==1,-100*pop/poptotal,100*pop/poptotal))%>%
mutate(grid_f=factor(grid,ordered=T,
levels=seq(0,90,5),
labels =c('0-4','5-9','10-14','15-19', '20-24', '25-29',
'30-34','35-39','40-44','45-49','50-54','55-59',
'60-64','65-69','70-74','75-79','80-84','85-89',
'90+')))%>%
mutate(COUNTRY_f=as_factor(COUNTRY),
SEX_f=as_factor(SEX))
th<-theme_ipsum()+
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=1,size=8),
axis.text.y = element_text(angle = 0, vjust = 0.5, hjust=1,size=8))
ggplot(data=dados,aes(x=grid_f,y=poprel,group=SEX_f,fill=SEX_f))+
geom_bar(stat='identity')+
coord_flip()+
facet_wrap(~COUNTRY_f)+
labs(caption = "Fonte: IMPUS International",
subtitle = 'Chile (2017) e Uruguay (2011)',
title='Pirâmide Etária')+
scale_y_continuous(name='População (%)',
labels=label_percent(big.mark = '.',decimal.mark = ','),
breaks = seq(-6,6,2),limits=c(-6,6))+
scale_x_discrete(name='Grupo de Idade')+
scale_fill_discrete(name='Sexo')+
th

ggplot(data=dados,aes(x=grid_f,y=poprel,group=SEX_f,fill=SEX_f))+
geom_bar(stat='identity')+
coord_flip()+
facet_wrap(~COUNTRY_f)+
labs(caption = "Fonte: IMPUS International",
subtitle = 'Chile (2017) e Uruguay (2011)',
title='Pirâmide Etária')+
scale_y_continuous(name='População (%)',
labels=label_number(big.mark = '.',decimal.mark = ','),
breaks = seq(-6,6,2),limits=c(-6,6))+
scale_x_discrete(name='Grupo de Idade')+
scale_fill_discrete(name='Sexo')+
th

dados_chile<-data%>%
mutate(grid=if_else(AGE>=90,90,
(trunc(AGE/5)*5)))%>%
filter(COUNTRY==152)%>%
group_by(SEX,grid,ETHNICCL)%>%
summarise(pop=sum(PERWT))%>%
ungroup()%>%
group_by(ETHNICCL)%>%
mutate(poptotal=sum(pop))%>%
mutate(poprel=if_else(SEX==1,-100*pop/poptotal,100*pop/poptotal))%>%
mutate(grid_f=factor(grid,ordered=T,
levels=seq(0,90,5),
labels =c('0-4','5-9','10-14','15-19', '20-24', '25-29',
'30-34','35-39','40-44','45-49','50-54','55-59',
'60-64','65-69','70-74','75-79','80-84','85-89',
'90+')))%>%
mutate(SEX_f=as_factor(SEX),
ETHNICCL_f=as_factor(ETHNICCL))
ggplot(data=dados_chile,aes(x=grid_f,y=poprel,group=SEX_f,fill=SEX_f))+
geom_bar(stat='identity')+
coord_flip()+
facet_wrap(~ETHNICCL_f)+
labs(caption = "Fonte: IMPUS International",
subtitle = 'Chile (2017)',
title='Pirâmide Etária')+
scale_y_continuous(name='População (%)',
labels=label_number(big.mark = '.',decimal.mark = ','),
breaks = seq(-6,6,2),limits=c(-6,6))+
scale_x_discrete(name='Grupo de Idade')+
scale_fill_discrete(name='Sexo')+
th

dados_1<-dados_chile%>%
group_by(ETHNICCL)%>%
summarise(pop=sum(pop))
dados_1
| 1 |
3140 |
| 2 |
30550 |
| 3 |
156620 |
| 4 |
20690 |
| 5 |
1739050 |
| 6 |
34300 |
| 7 |
8960 |
| 8 |
1850 |
| 9 |
89670 |
| 10 |
95870 |
| 99 |
15388290 |
dados_1<-dados_chile %>%
filter(ETHNICCL_f %in%
c('Aimara','Mapuche','Diaguita','Other indigenous'))
ggplot(data=dados_1,aes(x=grid_f,y=poprel,group=SEX_f,fill=SEX_f))+
geom_bar(stat='identity')+
coord_flip()+
facet_wrap(~ETHNICCL_f)+
labs(caption = "Fonte: IMPUS International",
subtitle = 'Chile (2017)',
title='Pirâmide Etária')+
scale_y_continuous(name='População (%)',
labels=label_number(big.mark = '.',decimal.mark = ','),
breaks = seq(-6,6,2),limits=c(-6,6))+
scale_x_discrete(name='Grupo de Idade')+
scale_fill_discrete(name='Sexo')+
th
