# NOT RUN {
data("Irish")
scale_by_rank <- function(x) apply(x, 2, rank)
x <- scale_by_rank(Irish[,-6])
# Use the the sum of absolute rank differences
order <- c(
seriate(dist(x, "minkowski", p = 1)),
seriate(dist(t(x), "minkowski", p = 1))
)
# Plot
bertinplot(x, order)
# Some alternative displays
bertinplot(x, order, panel = panel.tiles, shading_col = bluered(100), highlight = FALSE)
bertinplot(x, order, panel = panel.circles, spacing = -.2)
bertinplot(x, order, panel = panel.rectangles)
bertinplot(x, order, panel = panel.lines)
# Plot with cut lines (we manually set the order here)
order <- ser_permutation(c(21, 16, 19, 18, 14, 12, 20, 15,
17, 26, 13, 41, 7, 11, 5, 23, 28, 34, 31, 1, 38, 40,
3, 39, 4, 27, 24, 8, 37, 36, 25, 30, 33, 35, 2,
22, 32, 29, 10, 6, 9),
c(4, 2, 1, 6, 8, 7, 5, 3))
bertinplot(x, order, pop=FALSE)
bertin_cut_line(, 4) ## horizontal line between rows 4 and 5
bertin_cut_line(, 7) ## separate "Right to Life" from the rest
bertin_cut_line(14, c(0, 4)) ## separate a block of large values (vertically)
# ggplot2-based plots
if (require("ggplot2")) {
library(ggplot2)
# Default plot uses bars and highlighting values larger than the mean
ggbertinplot(x, order)
# highlight values in the 4th quartile
ggbertinplot(x, order, highlight = quantile(x, probs = .75))
# Use different geoms. "none" lets the user specify their own geom.
# Variables set are row, col and x (for the value).
ggbertinplot(x, order, geom = "tile", prop = TRUE)
ggbertinplot(x, order, geom = "rectangle")
ggbertinplot(x, order, geom = "rectangle", prop = TRUE)
ggbertinplot(x, order, geom = "circle")
ggbertinplot(x, order, geom = "line")
# Tiles with diverging color scale
ggbertinplot(x, order, geom = "tile", prop = TRUE) +
scale_fill_gradient2(midpoint = mean(x))
# Custom geom (geom = "none"). Defined variables are row, col, and x for the value
ggbertinplot(x, order, geom = "none", prop = FALSE) +
geom_point(aes(x = col, y = row, size = x, color = x > 30), pch = 15) +
scale_size(range = c(1, 10))
# Use a ggplot2 theme with theme_set()
old_theme <- theme_set(theme_minimal() +
theme(panel.grid = element_blank())
)
ggbertinplot(x, order, geom = "bar")
theme_set(old_theme)
}
# }
Run the code above in your browser using DataLab