#Introdução ao operador pipe
Gráfico de pizza no rbase e no pipe
# Passo 1 - Carregar a base de dados
load("C:/Users/Marcus Tulio/Desktop/MESTRADO2022_1/DISCIPLINAS/Estatistica/Mestrado_engenharia/Base_de_dados-master/Base_de_dados-master/Titanic.RData")
table(Titanic$Sobreviveu)
##
## Não sobreviveu Sobreviveu
## 1490 710
# Passo 2 - Gráfico de pizza - programação clássica
pie(table(Titanic$Sobreviveu))
pie(table(Titanic$Sobreviveu),col=c("red","blue"))
# Passo 3 - Gráfico de pizza com o 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
Titanic %>% select(Sobreviveu) %>% table() %>% pie(col=c("royalblue","orange"))
Desafio: Como fazer uma tabela da coluna B com a categoria A selecionada da coluna C
#Qauantos homens sobreviveram
Titanic %>%
filter(Sexo=="Masculino") %>%
select(Sobreviveu) %>%
table() %>%
pie(col=c("lightyellow","darkblue"))
###Desafio2: #Como colocar percentual na pizza?
contagem <- table(Titanic$Sobreviveu)
contagem
##
## Não sobreviveu Sobreviveu
## 1490 710
nomes <- levels(Titanic$Sobreviveu)
nomes
## [1] "Não sobreviveu" "Sobreviveu"
porcentagem <- round(contagem/sum(contagem)*100,3)
porcentagem
##
## Não sobreviveu Sobreviveu
## 67.727 32.273
rotulo <- paste0(nomes,"(",porcentagem,"%",")")
rotulo
## [1] "Não sobreviveu(67.727%)" "Sobreviveu(32.273%)"
# Construindo a pizza - pelo rbase
pie(table(Titanic$Sobreviveu),labels=rotulo)
# Construindo a pizza - pelo pipe
Titanic %>%
select(Sobreviveu) %>%
table() %>%
pie(labels = rotulo,col = c("red","yellow"))
###Desafio 3: Como fazer de uma forma diferente
library(waffle)
## Carregando pacotes exigidos: ggplot2
parte <- c(Não=68,Sim=32)
waffle(parte,rows=10,colors=c("red","blue"))
##Gráfico para Variável Quantitativa Discreta
library(readr)
Familias2 <- read_delim("C:/Users/Marcus Tulio/Desktop/MESTRADO2022_1/DISCIPLINAS/Estatistica/Mestrado_engenharia/Base_de_dados-master/Base_de_dados-master/Familias2.csv",
delim = ";", escape_double = FALSE, locale = locale(encoding = "WINDOWS-1252"),
trim_ws = TRUE)
## Rows: 120 Columns: 6
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (4): local, p.a.p, instr, renda
## dbl (2): familia, tam
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
stripchart(Familias2$tam,method = "stack",offset = .5,at = .15)
library(ggplot2)
ggplot(Familias2, aes(x = tam)) + geom_dotplot()
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
#Histograma ## Diferença entre Histograma e Gráfico de Barras
load("C:/Users/Marcus Tulio/Desktop/MESTRADO2022_1/DISCIPLINAS/Estatistica/Mestrado_engenharia/Base_de_dados-master/Base_de_dados-master/CARROS.RData")
par(mfrow=c(1,2))
hist(CARROS$Kmporlitro)
barplot(table(Titanic$Sobreviveu),col=c("red","blue"))
par(mfrow=c(1,1))
#Inrepretação do Histograma
hist(CARROS$Kmporlitro,
col = c("skyblue","skyblue","skyblue","red","red"),
main = "Histograma do Km/l",
ylab = "Frequência",
xlab = "Km/l")
hist(CARROS$Preco,
col = c("red"),
main = "Histograma do Preço do Carro",
ylab = "Frequência",
xlab = "Preço")
hist(CARROS$Preco,
breaks = 10,
col = c("red"),
main = "Histograma do Preço do Carro",
ylab = "Frequência",
xlab = "Preço")
hist(CARROS$Preco,
breaks = 10,
col = c("royalblue"),
main = "Histograma do Preço do Carro",
ylab = "Frequência",
xlab = "Preço",
labels = TRUE)
#Histograma do HP
par(bg="lightyellow")
hist(CARROS$HP,
col = c("purple"),
main = "Histograma do HP (Cavalos no Motor)",
ylab = "Frequência",
xlab = "HP",
labels = TRUE)
par(bg="white")
#Resumo Numérico das variaveis quantitativas
summary(CARROS$HP)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 52.0 96.5 123.0 146.7 180.0 335.0
summary(CARROS$Preco)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 71.1 120.8 196.3 230.7 326.0 472.0
summary(CARROS$Kmporlitro)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.40 15.43 19.20 20.09 22.80 33.90
Nessa aula, vimos uma estrategia de analise de dados para cada tipo de variavel.
Qualitativa Nominal - Pizza, waffle, tabela Qualitativa Ordinal - Barras, tabela Quantitativa Discreta - Dotplot, tabela Quantitativa Continua - Histograma e Resumo Numerico