2 VA

VADeaths

aux <- VADeaths
print(aux)
##       Rural Male Rural Female Urban Male Urban Female
## 50-54       11.7          8.7       15.4          8.4
## 55-59       18.1         11.7       24.3         13.6
## 60-64       26.9         20.3       37.0         19.3
## 65-69       41.0         30.9       54.6         35.1
## 70-74       66.0         54.3       71.1         50.0
cores <- c("yellow", "blue", "black", "white")

barplot(
  aux,
  main = "Gráfico de mortalidade (VA Death)",
  col = cores,
  beside = T,
  xlab = "Grupo de Pessoas",
  ylab = "Taxa Mortalidade",
  ylim = c(0,100)
)

legend(
  "topleft",                            
  legend = rownames(aux),
  fill = cores,                          
  title = "Faixa Etária",              
  bty = "n"
)

ClassificaçãoDoença

dados <- c(
  "moderado", "leve", "leve", "severo", 
  "leve","moderado", "moderado", "moderado", 
  "leve", "leve","severo", "leve", 
  "moderado", "moderado", "leve","severo", 
  "moderado", "moderado", "moderado", "leve"
)

rotulos <- c("leve", "moderado", "severo")

dados <- factor(dados, levels = c("leve", "moderado", "severo"))
contador <- table(dados)

aux <- prop.table(contador)
aux <- round(aux * 100, 1)
rotulos <- paste0(aux, "%")

print(rotulos)
## [1] "40%" "45%" "15%"
cores <- c("green", "orange", "red")

pie(
    main = "Classificação Doença",
    x = contador,
    labels = rotulos,
    col = cores,
    
    )

legend(
  "topright",
  legend = c("leve", "moderado", "severo"),
  fill = cores,
  title = "Nível da doença"
  
)

USArrests

library(plotly)
## Carregando pacotes exigidos: ggplot2
## 
## Anexando pacote: 'plotly'
## O seguinte objeto é mascarado por 'package:ggplot2':
## 
##     last_plot
## O seguinte objeto é mascarado por 'package:stats':
## 
##     filter
## O seguinte objeto é mascarado por 'package:graphics':
## 
##     layout
dados <- USArrests
dados$City <- rownames(dados)

ordemDecrescente <- dados[order(dados$Murder, decreasing = TRUE),]
aux <- ordemDecrescente[1:5,]

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

graf

Orange

dados_orange <- Orange
dados_orange$Tree <- factor(dados_orange$Tree, levels = c("1", "2", "3", "4", "5"))

plot_ly(
  data = dados_orange,
  x = ~age,
  y = ~circumference,
  color = ~Tree,
  mode = "lines",
  text = ~paste0("Árvore ", Tree, " - idade: ", age, " dias", " — circ.: ", circumference, " mm"),
  hoverinfo = "closest"
) %>%
  layout(
    title = "Crescimento ao longo do tempo",
    yaxis = list(title = "Circunferência em milímetros"),
    xaxis = list(title = "Idade em dias"),
    legend = list(title = list(text = "Árvore"))
  )
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plotly.com/r/reference/#scatter