aqui vamos fazer uma analise com duas variaveis

#passo 1- importação de dados

library(readxl)
Familias <- read_excel("C:/Users/usuario/Downloads/Base_de_dados-master/Base_de_dados-master/Familias.xls")
View(Familias)
head(Familias)
## # A tibble: 6 x 6
##   familia local       p.a.p   instr                tam renda
##     <dbl> <chr>       <chr>   <chr>              <dbl> <dbl>
## 1       1 Monte Verde Não usa Ensino médio           4  10.3
## 2       2 Monte Verde Não usa Ensino médio           4  15.4
## 3       3 Monte Verde Usa     Ensino fundamental     4   9.6
## 4       4 Monte Verde Não usa Ensino fundamental     5   5.5
## 5       5 Monte Verde Usa     Ensino médio           4   9  
## 6       6 Monte Verde Usa     Sem Instrução          1   2.4
library(readxl)
SERVPRO_2018_1 <- read_excel("C:/Users/usuario/Downloads/Base_de_dados-master/Base_de_dados-master/SERVPRO_2018_1.xlsx")
View(SERVPRO_2018_1)
head(SERVPRO_2018_1)
## # A tibble: 6 x 9
##      id grau_pagamento  sexo  raca casado idade anos_trabalho desempenho salário
##   <dbl>          <dbl> <dbl> <dbl>  <dbl> <dbl>         <dbl>      <dbl>   <dbl>
## 1     1              1     1     1      0    NA           0.5          2     890
## 2     2              1     1     0      0    25           2.4          3    1100
## 3     3              2     1     0      0    23           3.6          7    1070
## 4     4              1     0     1      0    26           1.9          3    1190
## 5     5              2     1     0      1    22           3.4          6    1290
## 6     6              1     1     1      1    23           2.8          4    1010

#passo 2- transformação de dados

SERVPRO_2018_1$sexo <- ifelse(SERVPRO_2018_1$sexo==0, "Masculino", "Feminino")
SERVPRO_2018_1$raca <- ifelse(SERVPRO_2018_1$raca==1, "Minoria", "Não minoria")
SERVPRO_2018_1$casado <- ifelse(SERVPRO_2018_1$casado==1, "Casado_a", "Solteiro_a")
SERVPRO_2018_1$grau_pagamento <- ifelse(SERVPRO_2018_1$grau_pagamento==1,"Junior",
                                 ifelse(SERVPRO_2018_1$grau_pagamento==2,"Pleno","Senior"))

#passo 3-

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
table(SERVPRO_2018_1$grau_pagamento)
## 
## Junior  Pleno Senior 
##    174    123    123
prop.table(table(SERVPRO_2018_1$grau_pagamento))
## 
##    Junior     Pleno    Senior 
## 0.4142857 0.2928571 0.2928571
SERVPRO_2018_1 %>% pull(grau_pagamento) %>% 
  table() %>% prop.table() %>% round(2)
## .
## Junior  Pleno Senior 
##   0.41   0.29   0.29
SERVPRO_2018_1 %>% pull(grau_pagamento) %>% 
  table() %>% barplot()

passo 4- tabelas

library(flextable)
library(reactable)
#tabela em numeros absolutos
Familias %>% select(local,p.a.p) %>% table() %>% data.frame() %>% flextable()
#tabela em numeros relativos
Familias %>% select(local,p.a.p) %>%
  table() %>% prop.table(2) %>% 
  data.frame() %>% flextable()

passo 5- graficos

Familias %>% select(local,p.a.p) %>%
  table() %>% barplot(beside = TRUE,
                      horiz= TRUE)

 library(RColorBrewer)
par(cex=0.7)
display.brewer.all()

COR <- brewer.pal(3,"Blues")
COR
## [1] "#DEEBF7" "#9ECAE1" "#3182BD"
Familias %>% select(local,p.a.p) %>%
  table() %>% barplot(beside = TRUE,
                      horiz= TRUE, col=COR)