rel.barplot.two <- function(n, col = 'grey40', col.number = 'white', density = NULL, border = 'black', xlab = '', ylab = 'Relative Frequency', main = '', names = rep('', dim(t(t(n)))[2]), legend = 1:dim(t(t(n)))[1], cex.main = 1.2, cex = 1, las = 1){ n <- t(t(n)) s <- apply(n, 2, sum) r <- t(t(n) / s) d <- dim(n)[1] b <- dim(n)[2] n <- n[d:1, ] s <- s[b:1] r <- r[d:1, ] v <- (lower.tri(matrix(1, d, d)) + 1 / 2 * diag(d)) %*% r x <- rep(0.5:(b - 0.5), rep(d, b), main = '', xlab = xlab) barplot(t(t(r)), width = 1, space = 0, density = density, col = col, border = border, ylim = c(0, 1), xlim = c(0, b + 1), xlab = '', ylab = ylab, names = names, main = '', cex.names = cex, axes = F ) legend('topright', fill = rev(col), density = density, legend = legend, bty = 'n', cex = cex) text(x = x, y = v, paste(round(n), '; ',round(r * 100, 2), '%', sep = ''), col = col.number, cex = cex) axis(2, las = T) mtext(main, side = 3, font = 2, line = 1.7, cex = cex.main) mtext(xlab, side = 1, font = 1, line = 2.5, cex = cex) }