Aqui vamos fazer uma análise com duas variáveis qualitativas.

Passo 1 - Importação de dados

library(readxl)
Familias <- read_excel("bases_curso_estatistica/Base_de_dados-master/Familias.xls")
View(Familias)
library(readxl)
SERVPRO_2018_1 <- read_excel("bases_curso_estatistica/Base_de_dados-master/SERVPRO_2018_1.xlsx")
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 - Tratamento dos dados

SERVPRO_2018_1$sexo <- ifelse (SERVPRO_2018_1$sexo==0, "Masculino",  "Feminino")
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", "Não casado_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 - Apresentando o operador pipe

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
SERVPRO_2018_1 %>% pull (grau_pagamento) %>% (table)
## .
## Junior  Pleno Senior 
##    174    123    123
prop.table(table (SERVPRO_2018_1$grau_pagamento))*100
## 
##   Junior    Pleno   Senior 
## 41.42857 29.28571 29.28571
round(prop.table(table (SERVPRO_2018_1$grau_pagamento)))*100
## 
## Junior  Pleno Senior 
##      0      0      0
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 - linha
Familias %>% select (local,p.a.p) %>% table () %>% prop.table(1) %>% data.frame() %>% flextable()
#Tabela em numeros relativos - coluna
Familias %>% select (local,p.a.p) %>% table () %>% prop.table(2) %>% data.frame() %>% flextable()

Grafico de barras

Familias %>% select(local,p.a.p) %>% table() %>% barplot()

library(RColorBrewer)
display.brewer.all()

COR <- brewer.pal(3,"Dark2")
COR
## [1] "#1B9E77" "#D95F02" "#7570B3"
graf_barras <- Familias %>% select(local,p.a.p) %>% table() %>% barplot(beside=TRUE,
                                                                        horiz=TRUE,
                                                                        col=COR)

graf_barras
##      [,1] [,2]
## [1,]  1.5  5.5
## [2,]  2.5  6.5
## [3,]  3.5  7.5
COR <- brewer.pal(3,"Dark2")
COR
## [1] "#1B9E77" "#D95F02" "#7570B3"