Seções com Abas

VADeaths
dados_longos <- VADeaths |>
  as.data.frame() |>
  rownames_to_column(var = "Faixa_Etaria") |>
  pivot_longer(
    cols = -Faixa_Etaria,
    names_to = "Grupo",
    values_to = "Taxa"
  )

str(dados_longos)
## tibble [20 × 3] (S3: tbl_df/tbl/data.frame)
##  $ Faixa_Etaria: chr [1:20] "50-54" "50-54" "50-54" "50-54" ...
##  $ Grupo       : chr [1:20] "Rural Male" "Rural Female" "Urban Male" "Urban Female" ...
##  $ Taxa        : num [1:20] 11.7 8.7 15.4 8.4 18.1 11.7 24.3 13.6 26.9 20.3 ...
valores <- matrix(dados_longos$Taxa,nrow = 5, ncol= 4, byrow = TRUE )
colorsz <- c("green","orange","red", "blue","purple")
GrupoAjustado <- dados_longos$Grupo[c(1,2,3,4)]
idade <- dados_longos$Faixa_Etaria[c(1,2,3,4,5)]

barplot(valores, main = "Mortes absolutas", names.arg =GrupoAjustado, xlab = "Grupo", ylab = "Mortes" , col = colorsz)
legend("topright", pch = c(15, 15, 15), col = c("green","orange","red", "blue","purple"), legend = idade)

ClassificaçãoDoença

Gráfico de pizza

triagem <-c("leve","moderado","severo")
pacientes <- c(8, 9, 3)
pct<-round(pacientes/sum(pacientes)*100)
lbls<-paste(triagem, pct)
lbls<-paste(lbls,"%",sep="")
pie(pacientes,labels=lbls, main="Classificação de estágio",col=rainbow(3))

USArrests
dados <- USArrests
dados$City <- rownames(dados)

top5_violentos <- dados %>%
  arrange(desc(Murder)) %>%
  head(5)

top5_violentos$City <- factor(top5_violentos$City, levels = top5_violentos$City)

fig <- plot_ly(top5_violentos, x = ~City, y = ~Murder, type = 'bar', name = 'Murder') %>%
  add_trace(y = ~Rape, name = 'Rape') %>%
  add_trace(y = ~Assault, name = 'Assault') %>%
  layout(
    title = '5 estados mais violentos (EUA, 1973)',
    xaxis = list(title = 'Estado'),
    yaxis = list(title = 'Ocorrências'),
    barmode = 'group'
  )

fig
Orange
data("Orange")
OrangeTree <- c()
OrangeTree <- factor(OrangeTree, levels = c("1", "2", "3", "4", "5"))

plot_ly(
  data = Orange,
  x = ~age,
  y = ~circumference,
  color = ~Tree,
  type = "scatter",
  mode = "lines+markers",
  text = ~paste0("Árvore ", Tree, " — idade: ", age, " dias — circ.: ", circumference, " mm"),
  hoverinfo = "text"
) %>%
  layout(
    title = "Crescimento das Laranjeiras",
    xaxis = list(title = "Idade (ano)"),
    yaxis = list(title = "Circunferência (mm)"),
    legend = list(title = list(text = "<b>Árvore</b>"))
  )