load("C:/Users/Myllena/Desktop/Base_de_dados-master/Titanic.RData")
# Passo2

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 ...
# Passo 3
pie(table(Titanic$Sobreviveu))

# Passo 4 - 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
# Passo 5
barplot(tabela_sexo)

barplot(tabela_sexo,main = "Grafico 1 - Sobrevivencia por sexo", col= c("black","pink"))

#Colors

library(RColorBrewer)
brewer.pal(5,"Blues")
## [1] "#EFF3FF" "#BDD7E7" "#6BAED6" "#3182BD" "#08519C"
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
COR <- c("#1B9E77", "#D95F02","#1B9E77", "#D95F02")
barplot(tabela_sexo,main ="Gráfico 1 - Sobrevivência por sexo",
        col = COR,horiz =FALSE,beside=TRUE,
        legend = rownames(tabela_sexo))

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

#-------------------------------------------------------------------
# Verificar a tese da desigualdade da sobrevivência
#---------------------------------------------------------------

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

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_classe <- Titanic %>% select(Classe,Sobreviveu) %>% table() 

tabela_classe_prop <- Titanic %>% select(Classe,Sobreviveu) %>% table() %>%
  prop.table(1) %>% round(2)


COR3 <- brewer.pal(4,"Set2")
tabela_classe %>% barplot(beside=T,
                          col=COR3,
                          main= "Gráfico 3",
                          legend = rownames(tabela_classe))