library(readxl)
global_shark_attack <- read_excel("C:/Users/Gabriela/Downloads/global-shark-attack.xlsx")
library(readxl)
CODIGO_PARA_MAPA <- read_excel("C:/Users/Gabriela/Downloads/CODIGO_PARA_MAPA.xlsx")
## New names:
## • `Country` -> `Country...2`
## • `` -> `...3`
## • `Country` -> `Country...4`
library(rworldmap)
## Warning: package 'rworldmap' was built under R version 4.3.2
## Carregando pacotes exigidos: sp
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, were retired in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
tub <- joinCountryData2Map(CODIGO_PARA_MAPA
, joinCode = "ISO3"
, nameJoinColumn = "ISO3V10" )
## 149 codes from your data successfully matched countries in the map
## 0 codes from your data failed to match with a country code in the map
## 94 codes from the map weren't represented in your data
cor <- RColorBrewer::brewer.pal(5,'RdPu')
mapCountryData( tub, nameColumnToPlot="n",colourPalette =cor,
mapTitle ="Ataque de Tubarão")
## You asked for 7 quantiles, only 3 could be created in quantiles classification
## Warning in rwmGetColours(colourPalette, numColours): 5 colours specified and 3
## required, using interpolation to calculate colours
library(forcats)
## Warning: package 'forcats' was built under R version 4.3.2
global_shark_attack$lesao = global_shark_attack$Injury %>%
fct_lump_n(5)
table(global_shark_attack$lesao)
##
## FATAL Foot bitten Leg bitten No injury Survived Other
## 862 100 82 89 97 5623
global_shark_attack$atividade = global_shark_attack$Activity %>%
fct_lump_n(5)
table(global_shark_attack$atividade)
##
## Fishing Spearfishing Surfing Swimming Wading Other
## 498 387 1112 1009 171 3127
#Gráfico 2
tabela = table(global_shark_attack$lesao,global_shark_attack$atividade)
barplot(tabela,beside = T,legend.text = rownames(tabela),args.legend = list(x = "topleft"),
col=c("red","tomato3","tomato2","skyblue","blue","darkblue"))
global_shark_attack$fatal = ifelse(global_shark_attack$`Fatal (Y/N)`=="y","Sim",
ifelse(global_shark_attack$`Fatal (Y/N)`=="Y","Sim",
ifelse(global_shark_attack$`Fatal (Y/N)`=="n","Não",
ifelse(global_shark_attack$`Fatal (Y/N)`=="N","Não",NA))))
table(global_shark_attack$fatal)
##
## Não Sim
## 4805 1448
global_shark_attack$Sexo= ifelse(global_shark_attack$Sex=="F","feminino",
ifelse(global_shark_attack$Sex=="M","masculino",NA))
table(global_shark_attack$Sexo)
##
## feminino masculino
## 768 5545
library(forcats)
global_shark_attack$especie = global_shark_attack$Species %>%
fct_lump_n(5)
pie(table(global_shark_attack$especie))
chisq.test(global_shark_attack$atividade,global_shark_attack$lesao)
## Warning in chisq.test(global_shark_attack$atividade,
## global_shark_attack$lesao): Aproximação do qui-quadrado pode estar incorreta
##
## Pearson's Chi-squared test
##
## data: global_shark_attack$atividade and global_shark_attack$lesao
## X-squared = 270.77, df = 25, p-value < 2.2e-16