tufte_boxplot: A variant of boxplot proposed by Edward Tufte.

View source: R/tufte_boxplot.R

tufte_boxplotR Documentation

A variant of boxplot proposed by Edward Tufte.

Description

A variant of boxplot proposed by Edward Tufte.

Usage

tufte_boxplot(data, ...)

Arguments

data

data frame to use for plot.

...

list of elements which will be added to the (gg)plot

Examples

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)


gibonet/ggstrusi documentation built on Jan. 13, 2024, 4:13 a.m.