VADeaths
# Fazendo o grafico de barras
bp <- barplot(
VADeaths,
beside = TRUE,
col = c("brown4", "brown", "brown3", "brown2", "brown1"),
main = "Taxas de Mortalidade - VADeaths",
xlab = "Faixa Etária",
ylab = "Taxa de Mortalidade",
xpd = TRUE
)
# Fazendo as legendas
legend(
x = max(bp) + 2,
y = max(VADeaths),
legend = rownames(VADeaths),
title = "Categorias",
fill = c("brown4", "brown", "brown3", "brown2", "brown1"),
bty = "n"
)

ClassificaçãoDoença
# Frequências
freq <- c(
Leve = 8,
Moderado = 9,
Severo = 3)
pct <- round(freq / sum(freq) * 100, 1)
cores <- c("green2", "orange", "red2")
pie(
freq,
labels = paste0(pct, "%"),
col = cores,
main = "Classificação da Doença")
legend(
"topright",
legend = names(freq),
fill = cores,
title = "Estágio da Doença",
bty = "n")

USArrests
library(dplyr)
library(plotly)
df <- USArrests
df$City <- rownames(df)
top5 <- df %>%
arrange(desc(Murder)) %>%
slice(1:5)
plot_ly(top5, x = ~City) %>%
add_bars(y = ~Murder, name = "Murder",
marker = list(color = "steelblue")) %>%
add_bars(y = ~Rape, name = "Rape",
marker = list(color = "orange2")) %>%
add_bars(y = ~Assault, name = "Assault",
marker = list(color = "green4")) %>%
layout(
barmode = "group",
title = list(text = "Top 5 estados mais violentos do EUA - 1973"),
xaxis = list(title = "Estado"),
yaxis = list(title = "Ocorrências")
)
Orange
library(plotly)
plot_ly() %>%
add_lines(
data = subset(Orange, Tree == 1),
x = ~age,
y = ~circumference,
name = "Árvore 1",
text = ~paste0(
"Árvore 1",
"<br>idade: ", age, " dias",
"<br>circ.: ", circumference, " mm"
),
hovertemplate = "%{text}<extra></extra>") %>%
add_lines(
data = subset(Orange, Tree == 2),
x = ~age,
y = ~circumference,
name = "Árvore 2",
text = ~paste0(
"Árvore 2",
"<br>idade: ", age, " dias",
"<br>circ.: ", circumference, " mm"),
hovertemplate = "%{text}<extra></extra>") %>%
add_lines(
data = subset(Orange, Tree == 3),
x = ~age,
y = ~circumference,
name = "Árvore 3",
text = ~paste0(
"Árvore 3",
"<br>idade: ", age, " dias",
"<br>circ.: ", circumference, " mm"),
hovertemplate = "%{text}<extra></extra>") %>%
add_lines(
data = subset(Orange, Tree == 4),
x = ~age,
y = ~circumference,
name = "Árvore 4",
text = ~paste0(
"Árvore 4",
"<br>idade: ", age, " dias",
"<br>circ.: ", circumference, " mm"),
hovertemplate = "%{text}<extra></extra>") %>%
add_lines(
data = subset(Orange, Tree == 5),
x = ~age,
y = ~circumference,
name = "Árvore 5",
text = ~paste0(
"Árvore 5",
"<br>idade: ", age, " dias",
"<br>circ.: ", circumference, " mm"),
hovertemplate = "%{text}<extra></extra>") %>%
layout(
title = "Crescimento das Laranjeiras",
xaxis = list(title = "Idade (dias)"),
yaxis = list(title = "Circunferência (mm)"))