library(forcats)
library(ggplot2)
library(ggpubr)
load("D:/Desktop/Base_de_dados-master/Titanic.RData")
dim(Titanic)
## [1] 2200 4
table(Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## 1490 710
table(Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## 1490 710
round(prop.table(table(Titanic$Sobreviveu))*100,2)
##
## Não sobreviveu Sobreviveu
## 67.73 32.27
table(Titanic$Sobreviveu,Titanic$Sexo)
##
## Feminino Masculino
## Não sobreviveu 126 1364
## Sobreviveu 344 366
table(Titanic$Sobreviveu,Titanic$Idade)
##
## criança adulto
## Não sobreviveu 52 1438
## Sobreviveu 57 653
table(Titanic$Sobreviveu,Titanic$Classe)
##
## Tripulação Primeira Segunda Terceira
## Não sobreviveu 673 122 167 528
## Sobreviveu 212 202 118 178
round(prop.table(table(Titanic$Sobreviveu,Titanic$Sexo),2)*100,2)
##
## Feminino Masculino
## Não sobreviveu 26.81 78.84
## Sobreviveu 73.19 21.16
round(prop.table(table(Titanic$Sobreviveu,Titanic$Idade),2)*100,2)
##
## criança adulto
## Não sobreviveu 47.71 68.77
## Sobreviveu 52.29 31.23
round(prop.table(table(Titanic$Sobreviveu,Titanic$Classe),2)*100,2)
##
## Tripulação Primeira Segunda Terceira
## Não sobreviveu 76.05 37.65 58.60 74.79
## Sobreviveu 23.95 62.35 41.40 25.21
tabela_sobreviveu<-table(Titanic$Sobreviveu)
barplot(tabela_sobreviveu,
beside=TRUE,
col=c("red","blue"),
main = "Sobreviventes (Titanic)",
ylim = c(0,2000),ylab="Pessoas a bordo",xlab="Status Pós-Acidente",
legend.text = TRUE)
bp <- barplot(tabela_sobreviveu,
beside=TRUE,
col=c("red","blue"),
main = "Sobreviventes (Titanic)",
ylim = c(0,2000),ylab="Pessoas a bordo",xlab="Status Pós-Acidente",
legend.text = TRUE)
rotulo <- paste0(round(prop.table(tabela_sobreviveu)*100,2),"%")
text (bp, 0, rotulo, cex = 0.7, pos = 3, col = "white")
Titanic$Sexo<-factor(Titanic$Sexo, levels = c("Masculino","Feminino"))
tabela_sobreviveu_sexo<-table(Titanic$Sobreviveu,Titanic$Sexo)
bp <- barplot(tabela_sobreviveu_sexo,
beside=TRUE,
col=c("red","blue"),
main = "Sexo dos Sobreviventes (Titanic)",
ylim = c(0,1400),ylab="Pessoas a bordo",xlab="Sexo",
legend.text = TRUE)
rotulo <- paste0(round(prop.table(tabela_sobreviveu_sexo)*100,2),"%")
text (bp, 0, rotulo, cex = 0.7, pos = 3, col = "white")
tabela<-table(Titanic$Classe,Titanic$Sobreviveu)
tabela<-data.frame(tabela)
ggballoonplot(tabela, fill = "value")+
ggtitle("Sobreviventes do Titanic")
tabela<-table(Titanic$Classe,Titanic$Sobreviveu)
mosaicplot(tabela, main = "Sobreviventes (Titanic)",
color = c("red","blue"))
Titanic$Sexo<-factor(Titanic$Sexo, levels = c("Masculino","Feminino"))
tabela_classe_sexo<-table(Titanic$Classe,Titanic$Sexo)
bp2 <- barplot(tabela_classe_sexo,
beside=TRUE,
col=c("yellow","gray", "skyblue", "pink"),
main = "Sexo e Classe das pessoas a bordo (Titanic)",
ylim = c(0,1000),ylab="Pessoas a bordo",xlab="Sexo",
legend.text = TRUE)
rotulo2 <- paste0(round(prop.table(tabela_classe_sexo)*100,2),"%")
text (bp2, 0, rotulo2, cex = 0.7, pos = 3, col = "black")
####Através da plotagem deste gráfico, pode-se perceber que a maioria das pessoas presentes no acidente do Titanic morreu. Numa análise relativa por classe, pode-se afirmar que o maior índice de mortes foi na Tripulação, seguida da 3ª, 2ª e 1ª classes, nesta ordem; sendo a 1ª classe a única em que a maioria conseguiu sobreviver ao acidente.
table(Titanic$Classe,Titanic$Idade)
##
## criança adulto
## Tripulação 0 885
## Primeira 6 318
## Segunda 24 261
## Terceira 79 627
table(Titanic$Classe,Titanic$Sexo)
##
## Masculino Feminino
## Tripulação 862 23
## Primeira 179 145
## Segunda 179 106
## Terceira 510 196
table(Titanic$Classe,Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## Tripulação 673 212
## Primeira 122 202
## Segunda 167 118
## Terceira 528 178
table(Titanic$Idade,Titanic$Sexo)
##
## Masculino Feminino
## criança 64 45
## adulto 1666 425
table(Titanic$Idade,Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## criança 52 57
## adulto 1438 653
table(Titanic$Sexo,Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## Masculino 1364 366
## Feminino 126 344