Barras
# Carregando bibliotecas necessárias
library(ggplot2)
# Criando o dataframe
dados <- data.frame(
Animal = c("Escorpião", "Serpente", "Aranha", "Outros animais", "Total"),
Total = c(8208, 4944, 4661, 5834, 23647),
Porcentagem = c(34.71, 20.91, 19.71, 24.67, 100.00)
)
# Removendo a linha "Total" para os gráficos
dados_grafico <- dados[dados$Animal != "Total", ]
# Definindo cores personalizadas
cores <- c("#FF6B6B", "#4ECDC4", "#45B7D1", "#FFA07A")
# Gráfico de Barras
grafico_barras <- ggplot(dados_grafico, aes(x = reorder(Animal, -Total), y = Total, fill = Animal)) +
geom_bar(stat = "identity", width = 0.7) +
scale_fill_manual(values = cores) +
labs(
title = "Casos de Intoxicação por Tipo de Animal",
subtitle = "Distribuição total de casos registrados",
x = "Tipo de Animal",
y = "Número de Casos",
fill = "Animal"
) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
plot.subtitle = element_text(hjust = 0.5, size = 12, color = "gray40"),
axis.text.x = element_text(angle = 45, hjust = 1, size = 10),
axis.title = element_text(size = 12, face = "bold"),
legend.position = "right"
) +
geom_text(aes(label = Total), vjust = -0.5, size = 4)
print(grafico_barras)

Pizza
# Gráfico de Pizza
par(mar = c(2, 2, 3, 2))
pie(dados_grafico$Total,
labels = paste0(dados_grafico$Animal, "\n", dados_grafico$Porcentagem, "%"),
col = cores,
main = "Distribuição Percentual de Casos de Intoxicação por Animal",
cex.main = 1.3,
font.main = 2,
border = "white",
radius = 1)
# Adicionando legenda ao gráfico de pizza
legend("topright",
legend = dados_grafico$Animal,
fill = cores,
cex = 0.9,
bty = "n")
