Carregar dados

load("C:/Users/Maysa Godoy/Desktop/Base_de_dados-master/Titanic.RData")

Inspecionar os dados

str(Titanic)
## 'data.frame':    2200 obs. of  4 variables:
##  $ Classe    : Factor w/ 4 levels "Tripulação","Primeira",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Idade     : Factor w/ 2 levels "criança","adulto": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Sexo      : Factor w/ 2 levels "Feminino","Masculino": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Sobreviveu: Factor w/ 2 levels "Não sobreviveu",..: 2 2 2 2 2 2 2 2 2 2 ...

Gráfico de pizza

pie(table(Titanic$Sobreviveu))

Tabelas

tabela_sexo <- table(Titanic$Sexo,Titanic$Sobreviveu)
tabela_idade <- table(Titanic$Idade,Titanic$Sobreviveu)

tabela_sexo
##            
##             Não sobreviveu Sobreviveu
##   Feminino             126        344
##   Masculino           1364        366
tabela_idade
##          
##           Não sobreviveu Sobreviveu
##   criança             52         57
##   adulto            1438        653
prop.table(tabela_sexo,1)
##            
##             Não sobreviveu Sobreviveu
##   Feminino       0.2680851  0.7319149
##   Masculino      0.7884393  0.2115607
prop.table(tabela_sexo,2)
##            
##             Não sobreviveu Sobreviveu
##   Feminino      0.08456376 0.48450704
##   Masculino     0.91543624 0.51549296
prop.table(tabela_idade,1)*100
##          
##           Não sobreviveu Sobreviveu
##   criança       47.70642   52.29358
##   adulto        68.77092   31.22908
prop.table(tabela_idade,2)*100
##          
##           Não sobreviveu Sobreviveu
##   criança       3.489933   8.028169
##   adulto       96.510067  91.971831

Gráfico de barras

barplot(tabela_sexo,main = "Gráfico 1 - Sobrevivência por sexo",
        col= c("LIGHTBLUE","LIGHTGREEN","LIGHTBLUE","LIGHTGREEN"),horiz = FALSE,beside = TRUE,
        legend = rownames(tabela_sexo)) 

barplot(tabela_idade,main = "Gráfico 2 - Sobrevivência por idade",
        col= c("red","blue","red","blue"),horiz = FALSE,beside = TRUE,
        legend = rownames(tabela_idade)) 

Cores

library(RColorBrewer)
#brewer.pal(5,"Blues")
#display.brewer.all()

COR <- brewer.pal(2,"Dark2")
## Warning in brewer.pal(2, "Dark2"): minimal value for n is 3, returning requested palette with 3 different levels

Verificar a tese da desigualdade da sobrevivência

barplot(round(prop.table(table(Titanic$Classe,Titanic$Sobreviveu),1),1)*100)

Executar DPLYR

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

Tabela em números absolutos

tabela_classe <- Titanic %>% select(Classe,Sobreviveu) %>% table() 
tabela_classe
##             Sobreviveu
## Classe       Não sobreviveu Sobreviveu
##   Tripulação            673        212
##   Primeira              122        202
##   Segunda               167        118
##   Terceira              528        178

Tabela em proporção

tabela_classe_prop <- Titanic %>% select(Classe,Sobreviveu) %>% table() %>%
  prop.table(1) %>% round(2)
tabela_classe_prop
##             Sobreviveu
## Classe       Não sobreviveu Sobreviveu
##   Tripulação           0.76       0.24
##   Primeira             0.38       0.62
##   Segunda              0.59       0.41
##   Terceira             0.75       0.25

Gráfico de barras por grupo

COR3 <- brewer.pal(4,"Set2")
tabela_classe %>% barplot(beside=T,
                          col=COR3,
                          main="Gráfico 3",
                          legend = rownames(tabela_classe),
                          ylim=c(0,1000),
                          args.legend = list(x = "topright"))