Gráficos

VADeaths

Barras agrupadas na horizontal, com tons de rosa do mais claro (faixa mais jovem) ao mais escuro (faixa mais velha).

VADeaths
##       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
par(bg = "#fff5f8", mar = c(5, 9, 4, 2))
barplot(VADeaths,
        beside = TRUE,
        horiz = TRUE,
        col = rosas,
        border = "white",
        las = 1,
        xlim = c(0, 80),
        main = "Taxa de mortalidade na Virgínia (1940)",
        col.main = "#880e4f",
        xlab = "Mortes por 1000 habitantes",
        ylab = "",
        legend.text = rownames(VADeaths),
        args.legend = list(title = "Faixa etária", x = "bottomright",
                           bg = "white", box.col = "#f06292"))
mtext("Grupo populacional", side = 2, line = 7.5)
abline(v = seq(0, 80, 20), col = "#f8bbd0", lty = 3)

ClassificaçãoDoença

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

freq <- table(factor(estagios, levels = c("leve", "moderado", "severo")))
freq
## 
##     leve moderado   severo 
##        8        9        3
porcent <- round(100 * prop.table(freq), 1)
rotulos <- paste0(porcent, "%\n(", freq, " pacientes)")
cores_pizza <- c("#f8bbd0", "#f06292", "#880e4f")

par(bg = "#fff5f8")
pie(freq,
    labels = rotulos,
    col = cores_pizza,
    border = "white",
    lwd = 3,
    init.angle = 90,
    clockwise = TRUE,
    main = "Classificação da Doença (n = 20)",
    col.main = "#880e4f")

legend("topright",
       legend = names(freq),
       fill = cores_pizza,
       border = "white",
       title = "Estágio",
       bg = "white", box.col = "#f06292")

USArrests

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

top5 <- dados[order(dados$Murder, decreasing = TRUE), ]
top5 <- head(top5, 5)
top5
##                Murder Assault UrbanPop Rape           City
## Georgia          17.4     211       60 25.8        Georgia
## Mississippi      16.1     259       44 17.1    Mississippi
## Florida          15.4     335       80 31.9        Florida
## Louisiana        15.4     249       66 22.2      Louisiana
## South Carolina   14.4     279       48 22.5 South Carolina
# Cores, título, legenda e eixos reproduzindo a figura da questão.
plot_ly(top5,
        x = ~City, y = ~Murder,
        type = "bar", name = "Murder",
        marker = list(color = "rgb(76,116,175)")) %>%
  add_trace(y = ~Rape, name = "Rape",
            marker = list(color = "rgb(229,136,55)")) %>%
  add_trace(y = ~Assault, name = "Assault",
            marker = list(color = "rgb(88,158,65)")) %>%
  layout(title = list(text = "5 estados mais violentos (EUA, 1973)",
                      x = 0.5, xanchor = "center"),
         xaxis = list(title = "Estado", categoryorder = "array",
                      categoryarray = top5$City,
                      showline = TRUE, linecolor = "#aaaaaa"),
         yaxis = list(title = "Ocorrências", range = c(0, 360),
                      tick0 = 0, dtick = 100,
                      gridcolor = "#eeeeee", zeroline = FALSE),
         barmode = "group",
         legend = list(x = 1.02, y = 1, xanchor = "left"),
         plot_bgcolor = "white",
         paper_bgcolor = "white",
         font = list(family = "Arial", color = "#404040"),
         margin = list(l = 65, r = 100, t = 60, b = 60))

Orange

Linhas suavizadas (spline) com marcadores em losango.

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

plot_ly(laranjas,
        x = ~age, y = ~circumference,
        color = ~Tree,
        colors = c("#f48fb1", "#ec407a", "#d81b60", "#ad1457", "#6a1b4d"),
        type = "scatter", mode = "lines+markers",
        line = list(shape = "spline", width = 3),
        marker = list(symbol = "diamond", size = 9,
                      line = list(color = "white", width = 1)),
        text = ~paste0("Árvore ", Tree, " — idade: ", age,
                       " dias — circ.: ", circumference, " mm"),
        hoverinfo = "text") %>%
  layout(title = list(text = "Crescimento das laranjeiras",
                      font = list(color = "#880e4f")),
         xaxis = list(title = "Idade (dias)", gridcolor = "#f8bbd0"),
         yaxis = list(title = "Circunferência (mm)", gridcolor = "#f8bbd0"),
         legend = list(title = list(text = "Árvore")),
         hoverlabel = list(bgcolor = "#fce4ec", font = list(color = "#880e4f")),
         plot_bgcolor = "#fff5f8",
         paper_bgcolor = "#fff5f8")