View source: R/tufte_boxplot.R
tufte_boxplot | R Documentation |
A variant of boxplot proposed by Edward Tufte.
tufte_boxplot(data, ...)
data |
data frame to use for plot. |
... |
list of elements which will be added to the (gg)plot |
data(c02_14)
str(c02_14)
# 1. Una linea tra il p90 e il p75
# 2. Un punto per la mediana (p50)
# 3. Una linea tra il p25 e il p10
g1 <- ggplot2::geom_linerange(ggplot2::aes(x = "", ymin = p75, ymax = p90))
g2 <- ggplot2::geom_point(ggplot2::aes(x = "", y = p50))
g3 <- ggplot2::geom_linerange(ggplot2::aes(x = "", ymin = p10, ymax = p25))
# E metto g1, g2 e g3 in una lista
g_tufte <- list(g1, g2, g3)
# E faccio il grafico con un gruppo (una riga del data frame)
tufte_boxplot(c02_14[1, ], g_tufte)
# Un altro esempio, stavolta utilizzando tutti i gruppi
# Sull'asse delle x tutti i gruppi di salariati, ordinati secondo il salario mediano
# Aggiungo una colonna che 'identifica' ogni riga
c02_14$id2 <- as.integer(row.names(c02_14))
g1 <- ggplot2::geom_linerange(ggplot2::aes(x = reorder(id2, p50), ymin = p75, ymax = p90))
g2 <- ggplot2::geom_point(ggplot2::aes(x = reorder(id2, p50), y = p50))
g3 <- ggplot2::geom_linerange(ggplot2::aes(x = reorder(id2, p50), ymin = p10, ymax = p25))
g_tufte <- list(g1, g2, g3)
tufte_boxplot(c02_14, g_tufte)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.