Title: | Variable Width Bar Charts: Bar Mekko |
---|---|
Description: | Create variable width bar charts i.e. "bar mekko" charts to include important quantitative context. Closely related to mosaic, spine (or spinogram), matrix, submarine, olympic, Mondrian or product plots and tree maps. |
Authors: | Eric Rynerson [cre, aut], Julius Vainora [ctb] |
Maintainer: | Eric Rynerson <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-03-06 03:17:43 UTC |
Source: | https://github.com/ryninho/mekko |
A smarter bar chart.
barmekko(data, x, y, width, values = FALSE)
barmekko(data, x, y, width, values = FALSE)
data |
A data frame. |
x |
A categorical variable defining the width categories. |
y |
A numeric variable defining the bar height. |
width |
A numeric variable defining the bar widths |
values |
A boolean indicating whether to show value labels in bars |
A bar mekko constructed with ggplot2.
library(ggplot2) df <- data.frame( region = c('Northeast', 'Southeast', 'Central', 'West'), sales = c(1200, 800, 450, 900), avg_margin = c(3.2, -1.4, 0.1, 2.1) ) barmekko(df, region, avg_margin, sales) barmekko(df, region, avg_margin, sales) + labs(title = 'Margins by Region') barmekko(df[order(-df$sales),], region, avg_margin, sales) barmekko(df[order(-df$avg_margin),], region, avg_margin, sales)
library(ggplot2) df <- data.frame( region = c('Northeast', 'Southeast', 'Central', 'West'), sales = c(1200, 800, 450, 900), avg_margin = c(3.2, -1.4, 0.1, 2.1) ) barmekko(df, region, avg_margin, sales) barmekko(df, region, avg_margin, sales) + labs(title = 'Margins by Region') barmekko(df[order(-df$sales),], region, avg_margin, sales) barmekko(df[order(-df$avg_margin),], region, avg_margin, sales)
Calculate positions from widths.
positions(width)
positions(width)
width |
A numeric vector of bar widths. |
A numeric vector of bar positions.