2VA
VADeaths
library(ggplot2)
library(reshape2)
#Matriz para data frame formato longo
df <- melt(as.data.frame(VADeaths),
variable.name = "Grupo",
value.name = "Taxa_Mortalidade")
## No id variables; using all as measure variables
#Adicionar a coluna de faixa de idades
df$Faixa_Etaria <- rep(rownames(VADeaths), times = ncol(VADeaths))
#Exibir novo dataset
head(df)
## Grupo Taxa_Mortalidade Faixa_Etaria
## 1 Rural Male 11.7 50-54
## 2 Rural Male 18.1 55-59
## 3 Rural Male 26.9 60-64
## 4 Rural Male 41.0 65-69
## 5 Rural Male 66.0 70-74
## 6 Rural Female 8.7 50-54
ggplot(df, aes(x = Faixa_Etaria, y = Taxa_Mortalidade, fill = Grupo)) +
geom_bar(stat = "identity", position = "dodge") +
labs(
title = "Taxa de Mortalidade na VirgÃnia (VADeaths)",
x = "Faixa Etária",
y = "Taxa de Mortalidade",
fill = "Grupo"
) +
theme_minimal() +
scale_fill_brewer(palette = "Set2")

ClassificaçãoDoença
# Criando o vetor de estágios da doença
dados <- c("moderado", "leve", "leve", "severo", "leve", "moderado", "moderado", "moderado",
"leve", "leve", "severo", "leve", "moderado", "moderado", "leve", "severo",
"moderado", "moderado", "moderado", "leve")
contagem <- table(dados)
#Convertendo para porcentagem
porcentagens <- round(prop.table(contagem) * 100, 1)
#Rotulação
rotulos <- paste(names(contagem), "\n", porcentagens, "%")
cores <- c("blue", "pink", "purple")
# Gráfico
pie(contagem, labels = rotulos, col = cores, main = "Distribuição dos Estágios da Doença")
legend("topright", legend = names(contagem), fill = cores, title = "Estágios")

Teorema
flu_data <- read.csv("/Users/alison/Downloads/flu.csv")
if(!require(ggplot2)) install.packages("ggplot2")
if(!require(dplyr)) install.packages("dplyr")
## Loading required package: 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
library(ggplot2)
library(dplyr)
ggplot(flu_data, aes(x = age)) +
geom_histogram(aes(y = ..density..), bins = 30, fill = "orange", alpha = 0.6) +
geom_density(color = "blue", size = 1) +
labs(title = "Histograma e Curva de Densidade - Idade das Mortes",
x = "Idade", y = "Densidade") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

set.seed(123)
sample_means <- replicate(200, mean(sample(flu_data$age, size = 35, replace = TRUE)))
data.frame(sample_means) %>%
ggplot(aes(x = sample_means)) +
geom_histogram(aes(y = ..density..), bins = 30, fill = "green", alpha = 0.6) +
geom_density(color = "brown", size = 1) +
labs(title = "Histograma e Curva de Densidade - Médias das Amostras (n=35)",
x = "Média das Idades", y = "Densidade") +
theme_minimal()
