graph - How would you replicate this graphic in R -


i'm wondering how graph in r?

graph

i tought using geom_bar ggplot package. don't know how plot changing thickness , colors reflect growth years @ same time.

i'd appreciate ideas.

thank you.

here steps start. nothing special, rectangles. there lot of information going on in chart, of in text along sides, meaning chart isnt effective.

the useful info chart shows yearly change in colors. can below colored based on rectangle height.

but +1 finding way visualize data.

enter image description here

set.seed(1) nr <- 4 nc <- 50 mm <- matrix(sort(runif(nr * nc)) * 10, nr, nc) nn <- matrix(sort(runif(nr * nc), decreasing = true) * 10, nr, nc) mm <- do.call('rbind', l <- list(mm, nn))[order(sequence(sapply(l, nrow))), ]  yy <- 50 mm <- rbind(mm, yy - colsums(mm)) nr <- nrow(mm)  plot(0:nc, type = 'n', ylim = c(0, yy), bty = 'n', axes = false, ann = false) rect(s <- sequence(nc), 0, s + .95, mm[1, ], border = na,      col = as.numeric(cut(mm[1, ], breaks = seq(0, 15, 3)))) axis(1, s + .5, labels = s + 2000, lwd = 0, lwd.ticks = 1) axis(1, s, labels = na, lwd = 0, lwd.ticks = .5, tcl = -.2) # axis(2, las = 1, lwd = 0) mtext('share of private jobs', side = 2, @ = par('usr')[3], adj = 0) arrows(.5, 0, .5, yy, lwd = 2, xpd = na, length = .1) text(par('usr')[1:2] + c(.5, -.5), yy, labels = range(s) + 2000,      xpd = na, pos = 3, adj = 0)  yy <- matrix(0, 1, nc) (ii in 2:nr) {   yy <- colsums(rbind(yy, mm[ii - 1, ]))   rect(s, yy  + 1, s + .95, yy + mm[ii, ], border = na,         col = as.numeric(cut(mm[ii, ], breaks = seq(0, 15, 3)))) } 

(i hope no 1 submits junk charts :{ )

also here incredibly simple way. should have done first, ie, create sample data, pad rows, , let barplot take care of rest. lot less control on approach, though.

mm <- matrix(sort(runif(10)), 2) * 10 nn <- matrix(.5, 2, ncol(mm)) mm <- do.call('rbind', l <- list(mm, nn))[order(sequence(sapply(l, nrow))), ] yy <- 22 mm <- rbind(mm, yy - colsums(mm)) barplot(mm, col = 1:0, border = na, axes = false) 

enter image description here


Popular posts from this blog