O Sistema de Informações sobre Nascidos Vivos (SINASC) possui como objetivo de coletar dados sobre os nascimentos ocorridos em todo o território nacional e fornecer informações sobre natalidade para todos os níveis do Sistema de Saúde. O objetivo desse tutorial é coletar o total de nascimentos, calcular alguns indicadores relacionados e comparar com a natalidade nas projeções populacionais.

SINASC

Leitura dos pacotes

Carregue o pacote “microdatasus” e outros bibliotecas a serem usadas:

library(microdatasus)
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
library(readxl)
library(writexl)
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(ggplot2)

Microdados

Acesse os microdados de nascimentos especificando o período de análise e a UF a ser estudada:

dados_sinasc <- fetch_datasus(year_start = 2000, 
                           year_end = 2021, 
                           uf = "DF", 
                           information_system = "SINASC",
                           vars=c("DTNASC","IDADEMAE","SEXO"))
## Your local Internet connection seems to be ok.
## DataSUS FTP server seems to be up. Starting download...

Processe os dados do SINASC criando variáveis com a função process_sinasc:

dados_sinasc$SEXO[which(dados_sinasc$SEXO=="M")] <- 1
dados_sinasc$SEXO[which(dados_sinasc$SEXO=="F")] <- 2
dados_sinasc  <- process_sinasc(dados_sinasc)

Crie a variável de faixa etária:

dados_sinasc<- dados_sinasc %>% mutate(nasc = 1,
                      ano = as.numeric(substr(DTNASC,1,4)),
                      faixa_idade_mae = cut(as.numeric(IDADEMAE),c(-Inf,4,9,14,19,24,29,34,39,
                                                                    44,49,54,59,64,69,74,79,Inf),
                                                                  labels = c("até 4 anos","5 a 9 anos","10 a 14 anos",
                                                                             "15 a 19 anos","20 a 24 anos",
                                                                             "25 a 29 anos","30 a 34 anos","35 a 39 anos",
                                                                             "40 a 44 anos","45 a 49 anos","50 a 54 anos",
                                                                             "55 a 59 anos","60 a 64 anos","65 a 69 anos",
                                                                             "70 a 74 anos","75 a 79 anos","80 anos ou mais")),

                      faixa_idade_mae_15_49 = cut(as.numeric(IDADEMAE),c(-Inf,19,
                                                               24,29,34,
                                                              39,44,49),
                                                    labels = c("15 a 19 anos","20 a 24 anos",
                                                              "25 a 29 anos","30 a 34 anos","35 a 39 anos",
                                                              "40 a 44 anos","45 a 49 anos"))
)

Projeções populacionais

Lendo os dados das projeções populacionais especialmente da Unidade da Federação escolhida. O arquivo auxiliar está disponível aqui. Para todas as UFs, o arquivo do IBGE pode ser acessado aqui.

proj_ibge<- read_excel("indicadores_projecoes_DF_IBGE.xlsx")

proj_ibge<-ts(proj_ibge,start = 2010,frequency = 1)
proj_ibge<-window(proj_ibge,start = 2010,end=2030,frequency = 1)

Indicadores demográficos

Total de nascimentos

Sintetize um total de nascimentos para a Unidade da Federação escolhida:

# total de nascimentos para DF
aggregate(data=dados_sinasc,nasc~ano, FUN= sum) 
##     ano  nasc
## 1  2000 47991
## 2  2001 46891
## 3  2002 45799
## 4  2003 46097
## 5  2004 45593
## 6  2005 45917
## 7  2006 45152
## 8  2007 44098
## 9  2008 44173
## 10 2009 43932
## 11 2010 44251
## 12 2011 43465
## 13 2012 43497
## 14 2013 44530
## 15 2014 44721
## 16 2015 46122
## 17 2016 43340
## 18 2017 44568
## 19 2018 44195
## 20 2019 42422
## 21 2020 39361
## 22 2021 38035

Organize uma table com o total de nascimentos por sexo para a UF escolhida:

# tabela 1 - total de nascimentos e por sexo
tab1 <-dados_sinasc  %>%
  group_by(ano) %>%
  summarise(nasc = n())

tab1a<-dados_sinasc  %>%
  filter(SEXO=="Masculino")%>%
  group_by(ano) %>%
  summarise(nasc_masc = n())
tabela1<-merge(tab1,tab1a,by="ano")
rm(tab1,tab1a)

tab1b<-dados_sinasc  %>%
  filter(SEXO=="Feminino")%>%
  group_by(ano) %>%
  summarise(nasc_fem = n())
tabela1<-merge(tabela1,tab1b,by="ano")
rm(tab1b)

# ajuste com NA
tabela1$nasc_masc_ajust<-round(tabela1$nasc_masc/(tabela1$nasc_masc+tabela1$nasc_fem)*tabela1$nasc)
tabela1$nasc_fem_ajust<-round(tabela1$nasc_fem/(tabela1$nasc_masc+tabela1$nasc_fem)*tabela1$nasc)
# verifica se a soma é verdadeira
tabela1$nasc_fem_ajust+tabela1$nasc_masc_ajust==tabela1$nasc
##  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
tabela1
##     ano  nasc nasc_masc nasc_fem nasc_masc_ajust nasc_fem_ajust
## 1  2000 47991     24577    23375           24597          23394
## 2  2001 46891     23828    23001           23860          23031
## 3  2002 45799     23390    22378           23406          22393
## 4  2003 46097     23320    22646           23386          22711
## 5  2004 45593     23313    22227           23340          22253
## 6  2005 45917     23434    22454           23449          22468
## 7  2006 45152     23125    22024           23127          22025
## 8  2007 44098     22537    21559           22538          21560
## 9  2008 44173     22699    21470           22701          21472
## 10 2009 43932     22768    21157           22772          21160
## 11 2010 44251     22765    21480           22768          21483
## 12 2011 43465     22370    21090           22373          21092
## 13 2012 43497     22257    21231           22262          21235
## 14 2013 44530     22678    21835           22687          21843
## 15 2014 44721     22871    21843           22875          21846
## 16 2015 46122     23690    22419           23697          22425
## 17 2016 43340     22056    21280           22058          21282
## 18 2017 44568     22701    21859           22705          21863
## 19 2018 44195     22411    21773           22417          21778
## 20 2019 42422     21684    20729           21689          20733
## 21 2020 39361     20139    19217           20142          19219
## 22 2021 38035     19371    18658           19374          18661
write_xlsx(tabela1,"Tabela  1a - Total de nascimentos.xlsx")

Suavizando os dados com uma média móvel e plotando um gráfico:

tabela1<-ts(tabela1,start = 2000,frequency = 1)
tabela1m<-rollmean(x = tabela1,k = 3)

write_xlsx(as.data.frame(tabela1m),"Tabela  1b - Total de nascimentos com média móvel.xlsx")

ggplot(as.data.frame(tabela1m), aes(x=ano, y=nasc)) +
  geom_line( color="steelblue") +
  geom_point() +
  xlab("Ano")+
  ylab("Nascimentos")+
  ggtitle("Total de nascidos vivos - DF - 2000-2020 ")

Como você descreveria essa trajetória?

Com os dados das Projeções Populacionais, qual o total de nascimentos projetado até 2030?

ggplot(as.data.frame(proj_ibge), aes(x=ano, y=nasc)) +
  geom_line( color="steelblue") +
  geom_point() +
  xlab("Ano")+
  ylab("Nascimentos")+
  ggtitle("Total de nascidos vivos - DF - 2000-2020 ")

Comparando o total de nascimentos por fontes, tem-se:

ano1<-2010:2030
var1<-c(round(as.data.frame(tabela1)$nasc[11:21]),rep(NA,10))
var2<-c(round(as.data.frame(tabela1m)$nasc[10:19]),rep(NA,11))
var3<-as.data.frame(proj_ibge)$nasc
data1<-data.frame(ano1,var1,var2,var3)

p1<-ggplot(data1, aes(x=ano1)) +
  geom_line(aes(y=var1, col="SINASC"),linetype=1,size=1.2) +
  geom_line(aes(y=var2, col="SINASC-média móvel"),linetype=1,size=1.2) +
  geom_line(aes(y=var3, col="Proj. IBGE"),linetype=1,size=1.2) +
  labs(title="Total de nascidos vivos por fonte de dados - DF - 2010-2030", y="Total de nascidos vivos",x=element_blank()) +
  scale_color_manual(name="",
                     values = c("SINASC"="coral4",
                                "SINASC-média móvel"="coral3",
                                "Proj. IBGE"="darkblue")) +
  # ylim(0,NA)+
  theme(legend.position="bottom",axis.text.x = element_text(angle = 90))+
  scale_x_continuous(breaks=ano1, labels=ano1)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p1
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Warning: Removed 11 rows containing missing values (`geom_line()`).

png(filename = "Total de nascidos vivos por fonte de dados - DF - 2010-2030.png",
    width = 15, height = 8,
    units = "cm",res = 1200)
p1
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Removed 11 rows containing missing values (`geom_line()`).
dev.off()
## png 
##   2
write_xlsx(data1,"Tabela  1c - Total de nascimentos por fontes.xlsx")

Taxa Bruta de Natalidade

Calculando a Taxa Bruta de Natalidade:

# taxa bruta de natalidade
ano2<-2010:2030
var1<-c(round(as.data.frame(tabela1)$nasc[11:21]),rep(NA,10))/
  as.data.frame(proj_ibge)$pop_total*1000
var2<-c(round(as.data.frame(tabela1m)$nasc[10:19]),rep(NA,11))/
  as.data.frame(proj_ibge)$pop_total*1000
var3<-as.data.frame(proj_ibge)$tbn
data2<-data.frame(ano2,var1,var2,var3)

p2<-ggplot(data2, aes(x=ano2)) +
  geom_line(aes(y=var1, col="SINASC"),linetype=1,size=1.2) +
  geom_line(aes(y=var2, col="SINASC-média móvel"),linetype=1,size=1.2) +
  geom_line(aes(y=var3, col="Proj. IBGE"),linetype=1,size=1.2) +
  labs(title="Taxa Bruta de Natalidade por fonte de dados - DF - 2010-2030",
       y="TBN",x=element_blank()) +
  scale_color_manual(name="",
                     values = c("SINASC"="coral4",
                                "SINASC-média móvel"="coral3",
                                "Proj. IBGE"="darkblue")) +
  # ylim(0,NA)+
  theme(legend.position="bottom",axis.text.x = element_text(angle = 90))+
  scale_x_continuous(breaks=ano2, labels=ano2)
p2
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Warning: Removed 11 rows containing missing values (`geom_line()`).

png(filename = "Taxa Bruta de Natalidade por fonte de dados - DF - 2010-2030.png",
    width = 15, height = 8,
    units = "cm",res = 1200)
p2
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Removed 11 rows containing missing values (`geom_line()`).
dev.off()
## png 
##   2
write_xlsx(data2,"Tabela  1d - Taxa Bruta de Natalidade por fontes.xlsx")

Taxa de Fecundidade Geral

Para o cálculo a seguir, será necessário arquivo auxiliar com o total populacional das mulheres de 15 a 49 anos disponível aqui. O arquivo foi organizado a partir dos dados divulgados pelas Projeções Populacionais disponível aqui Calculando a taxa de fecundidade geral:

# taxa de fecundidade geral
library(readxl)
pop_m_15_49 <- read_excel("pop_m_15-49.xlsx")
pop_m_15_49<-ts(pop_m_15_49,start = 2010,frequency = 1)
pop_m_15_49<-window(pop_m_15_49,start=2010,end=2030)

ano3<-2010:2030
var1<-c(round(as.data.frame(tabela1)$nasc[11:21]),rep(NA,10))/
  as.data.frame(pop_m_15_49)$pop_m_15_49*1000
var2<-c(round(as.data.frame(tabela1m)$nasc[10:19]),rep(NA,11))/
  as.data.frame(pop_m_15_49)$pop_m_15_49*1000
var3<-as.data.frame(proj_ibge)$nasc/
  as.data.frame(pop_m_15_49)$pop_m_15_49*1000
data3<-data.frame(ano3,var1,var2,var3)

p3<-ggplot(data3, aes(x=ano3)) +
  geom_line(aes(y=var1, col="SINASC"),linetype=1,size=1.2) +
  geom_line(aes(y=var2, col="SINASC-média móvel"),linetype=1,size=1.2) +
  geom_line(aes(y=var3, col="Proj. IBGE"),linetype=1,size=1.2) +
  labs(title="Taxa de Fecundidade Geral por fonte de dados - DF - 2010-2030",
       y="TFG",x=element_blank()) +
  scale_color_manual(name="",
                     values = c("SINASC"="coral4",
                                "SINASC-média móvel"="coral3",
                                "Proj. IBGE"="darkblue")) +
  # ylim(0,NA)+
  theme(legend.position="bottom",axis.text.x = element_text(angle = 90))+
  scale_x_continuous(breaks=ano1, labels=ano1)


p3
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Warning: Removed 11 rows containing missing values (`geom_line()`).

png(filename = "Taxa de Fecundidade Geral por fonte de dados - DF - 2010-2030.png",
    width = 15, height = 8,
    units = "cm",res = 1200)
p3
## Warning: Removed 10 rows containing missing values (`geom_line()`).
## Removed 11 rows containing missing values (`geom_line()`).
dev.off()
## png 
##   2
write_xlsx(data3,"Tabela  1e - Taxa de Fecundidade Geral por fontes.xlsx")

Calculando o total de nascimentos por faixa etária da mãe:

# total de nascimentos para DF por faixa etaria da mae
tab2 <- dados_sinasc %>%
  group_by(ano,faixa_idade_mae_15_49) %>%
  summarise(
    nasc = n())
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
tab2a <- dados_sinasc %>%
  filter(SEXO=="Masculino")%>%
  group_by(ano,faixa_idade_mae_15_49) %>%
  summarise(
    nasc_h = n())
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
tabela2<-merge(tab2,tab2a,by=c("ano","faixa_idade_mae_15_49"))
rm(tab2,tab2a)

tab2b <- dados_sinasc %>%
  filter(SEXO=="Feminino")%>%
  group_by(ano,faixa_idade_mae_15_49) %>%
  summarise(
    nasc_m = n())
## `summarise()` has grouped output by 'ano'. You can override using the `.groups`
## argument.
tabela2<-merge(tabela2,tab2b,by=c("ano","faixa_idade_mae_15_49"))
rm(tab2b)

# visualizando para dois anos específicos
subset(tabela2,ano==2019)
##      ano faixa_idade_mae_15_49  nasc nasc_h nasc_m
## 151 2019          15 a 19 anos  4361   2168   2192
## 152 2019          20 a 24 anos  8682   4556   4124
## 153 2019          25 a 29 anos  9512   4883   4628
## 154 2019          30 a 34 anos 10128   5173   4954
## 155 2019          35 a 39 anos  7516   3820   3692
## 156 2019          40 a 44 anos  2078   1021   1057
## 157 2019          45 a 49 anos   129     55     74
## 158 2019                  <NA>    16      8      8
subset(tabela2,ano==2020)
##      ano faixa_idade_mae_15_49 nasc nasc_h nasc_m
## 159 2020          15 a 19 anos 3772   1910   1861
## 160 2020          20 a 24 anos 8053   4113   3937
## 161 2020          25 a 29 anos 8986   4615   4370
## 162 2020          30 a 34 anos 9209   4713   4496
## 163 2020          35 a 39 anos 7173   3678   3495
## 164 2020          40 a 44 anos 2017   1041    976
## 165 2020          45 a 49 anos  136     64     72
## 166 2020                  <NA>   15      5     10
subset(tabela2,ano==2021)
##      ano faixa_idade_mae_15_49 nasc nasc_h nasc_m
## 167 2021          15 a 19 anos 3323   1739   1582
## 168 2021          20 a 24 anos 7616   3903   3713
## 169 2021          25 a 29 anos 9027   4609   4417
## 170 2021          30 a 34 anos 8956   4490   4465
## 171 2021          35 a 39 anos 6915   3525   3390
## 172 2021          40 a 44 anos 2048   1023   1023
## 173 2021          45 a 49 anos  136     77     59
## 174 2021                  <NA>   14      5      9
# faz ajuste de NA - faixa da idade da mãe
table1<-as.data.frame(tabela1[,c("ano","nasc")])
colnames(table1)<-c("ano","nasc_total")
tabela2<-merge(tabela2,table1,by=c("ano"))
rm(table1)

table2 <- tabela2 %>%
  filter(!is.na(faixa_idade_mae_15_49))%>%
  group_by(ano) %>%
  summarise(
    nasc_sem_na = sum(nasc))

tabela2<-merge(tabela2,table2,by=c("ano"))

tabela2$part<-tabela2$nasc/tabela2$nasc_sem_na
tabela2$nasc_ajust<-round(tabela2$part*tabela2$nasc_total)

# quase arredondou para todos
tabela2 %>%
  filter(!is.na(faixa_idade_mae_15_49))%>%
  group_by(ano) %>%
  summarise(
    nasc_conf = sum(nasc_ajust))
## # A tibble: 22 × 2
##      ano nasc_conf
##    <dbl>     <dbl>
##  1  2000     47990
##  2  2001     46892
##  3  2002     45799
##  4  2003     46097
##  5  2004     45592
##  6  2005     45917
##  7  2006     45153
##  8  2007     44098
##  9  2008     44173
## 10  2009     43931
## # ℹ 12 more rows
tabela2$nasc_h_ajust<-round(tabela2$nasc_h/(tabela2$nasc_h+tabela2$nasc_m)*tabela2$nasc_ajust)
tabela2$nasc_m_ajust<-round(tabela2$nasc_m/(tabela2$nasc_h+tabela2$nasc_m)*tabela2$nasc_ajust)
# conferencia
tabela2$nasc_h_ajust+tabela2$nasc_m_ajust==tabela2$nasc_ajust
##   [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [37]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [49]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [61]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [73]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [85]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
##  [97]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [109]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [121]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [133]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [145]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [157]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [169]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
# traz dados de população por faixa etária
colnames(pop_m_15_49)
## [1] "ano"         "pop_m_15_49" "pop_m_15_19" "pop_m_20_24" "pop_m_25_29"
## [6] "pop_m_30_34" "pop_m_35_39" "pop_m_40_44" "pop_m_45_49"
library(tidyr)
## 
## Attaching package: 'tidyr'
## 
## The following object is masked _by_ '.GlobalEnv':
## 
##     table2
pop_m_wide<-as.data.frame(pop_m_15_49)
colnames(pop_m_wide)<- c("ano","15 a 49 anos" ,"15 a 19 anos" ,"20 a 24 anos",
                        "25 a 29 anos", "30 a 34 anos", "35 a 39 anos",
                        "40 a 44 anos",
                        "45 a 49 anos")
pop_m_long <- pop_m_wide %>% gather(faixa_idade_mae_15_49, pop_m, -c(ano)) # para fazer o merge coloca o nome faixa_idade_mae_15_49

tabela2<-merge(tabela2,pop_m_long,by=c("ano","faixa_idade_mae_15_49"))

Taxas Específicas de Fecundidade

Calculando as taxas específicas de fecundidade:

# Taxas Específicas de Fecundidade (TEFs) por idade (nfx)
tabela2$tef<-tabela2$nasc_ajust/tabela2$pop_m

table2<-spread(tabela2[,c("ano","faixa_idade_mae_15_49","nasc_ajust")],faixa_idade_mae_15_49,nasc_ajust)

table2<-ts(table2,start = 2010,frequency = 1)
table2m<-rollmean(x = table2,k = 3)

table2m<-as.data.frame(table2m) %>% gather(faixa_idade_mae_15_49, nasc_ajust_m, -c(ano)) # para fazer o merge coloca o nome faixa_idade_mae_15_49
tabela2<-merge(tabela2,table2m,by=c("ano","faixa_idade_mae_15_49"),all.x = TRUE)


tabela2$tef_m<-tabela2$nasc_ajust_m/tabela2$pop_m
tabela2$ano<-as.character(tabela2$ano)

data<-subset(tabela2,ano!=2010&ano!=2020)
p4<-ggplot(data, aes(x=faixa_idade_mae_15_49, y=tef_m,group=ano,color=ano)) +
  geom_line(linetype=1,size=1.2) +
  labs(title="Taxas Específicas de Fecundidade por ano - DF - 2010-2020",
       y="TEF",x=element_blank()) +
  # ylim(0,NA)+
  theme(legend.position="bottom",axis.text.x = element_text(angle = 90))


p4
## Warning: Removed 7 rows containing missing values (`geom_line()`).

png(filename = "Taxas Específicas de Fecundidade por ano - DF - 2010-2020.png",
    width = 15, height = 12,
    units = "cm",res = 1200)
p4
## Warning: Removed 7 rows containing missing values (`geom_line()`).
dev.off()
## png 
##   2
write_xlsx(tabela2,"Tabela  1f - Taxas Específicas de Fecundidade.xlsx")

Taxa de Fecundidade Total

Calculando a taxa de fecundidade total:

# Taxa de Fecundidade Total (TFT)
tabela3<-tabela2 %>%
  filter(!is.na(faixa_idade_mae_15_49))%>%
  group_by(ano) %>%
  summarise(
    tft = 5*sum(tef),
    tft_m = 5*sum(tef_m))


ano4<-2010:2030
var1<-c(tabela3$tft,rep(NA,9))
var2<-c(tabela3$tft_m,rep(NA,9))
var3<-as.data.frame(proj_ibge)$tft

data4<-data.frame(ano4,var1,var2,var3)

p5<- ggplot(data4, aes(x=ano4)) +
  geom_line(aes(y=var1, col="SINASC"),linetype=1,size=1.2) +
  geom_line(aes(y=var2, col="SINASC-média móvel"),linetype=1,size=1.2) +
  geom_line(aes(y=var3, col="Proj. IBGE"),linetype=1,size=1.2) +
  labs(title="Taxa de Fecundidade Total por fonte de dados - DF - 2010-2030",
       y="TFT",x=element_blank()) +
  scale_color_manual(name="",
                     values = c(
                       "SINASC"="coral4",
                                "SINASC-média móvel"="coral3",
                                "Proj. IBGE"="darkblue")) +
  # ylim(0,NA)+
  theme(legend.position="bottom",axis.text.x = element_text(angle = 90))+
  scale_x_continuous(breaks=ano4, labels=ano4)

p5
## Warning: Removed 9 rows containing missing values (`geom_line()`).
## Warning: Removed 11 rows containing missing values (`geom_line()`).

png(filename = "Taxa de Fecundidade Total por fonte de dados - DF - 2010-2030.png",
    width = 15, height = 12,
    units = "cm",res = 1200)
p5
## Warning: Removed 9 rows containing missing values (`geom_line()`).
## Removed 11 rows containing missing values (`geom_line()`).
dev.off()
## png 
##   2
write_xlsx(data4,"Tabela  1g - Taxa de Fecundidade Total por fontes.xlsx")