Questão 1
install.packages("ggplot2")
install.packages("tidyr")
## Warning: package 'htmltools' was built under R version 4.3.2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'tidyr' was built under R version 4.3.2
Carregando o dataset
data(VADeaths)
Criando o gráfico de barras empilhadas
p <- ggplot(df, aes(x = group, y = deaths, fill = group)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "VADeaths Dataset", x = "Groups", y = "Deaths", fill = "Group") +
theme_minimal()
Exibindo o gráfico
print(p)

Questão 2
# Dados
estagios <- c("moderado", "leve", "leve", "severo", "leve", "moderado", "moderado", "moderado", "leve", "leve", "severo","leve", "moderado", "moderado", "leve", "severo", "moderado", "moderado", "moderado","leve")
# Contagem de estágios
contagem <- table(estagios)
# Porcentagens
porcentagens <- round(prop.table(contagem) * 100, 1)
# Cores
cores <- c("leve" = "lightblue", "moderado" = "orange", "severo" = "red")
# Gráfico de pizza
pie(contagem, labels = paste(names(contagem), "\n", porcentagens, "%"), col = cores, main = "Estágios da doença")
# Legenda
legend("topright", legend = names(contagem), fill = cores)

Teorema
library(boot)
flu <- read.csv('flu.csv')
ggplot(flu, aes(x = age)) +
geom_histogram(fill = "darkorange") +
stat_density(color = "black", size = 1.2) +
labs(title = "Distribuição das idades das mortes na epidemia de gripe espanhola",
x = "Idade",
y = "Frequência")
## 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.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

amostras <- replicate(200, mean(sample(flu$age, 35)))
ggplot(data.frame(amostras = amostras), aes(x = amostras)) +
geom_histogram(fill = "skyblue") +
stat_density(color = "black", size = 1.2) +
labs(title = "Distribuição das médias de 200 amostras de tamanho 35",
x = "Média da idade",
y = "Frequência")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
