你会如何在R中复制这个图形

Jav*_*ier 2 plot r graph ggplot2

我想知道如何在R中做这个图?

图形

我考虑过使用ggplot包中的geom_bar.但是我不知道如何绘制变化的厚度和同时反映多年增长的颜色.

我很欣赏任何想法.

谢谢.

raw*_*awr 8

以下是一些开始的步骤.没什么特别的,只是一些矩形.此图表中有大量信息,大部分信息都在两侧的文本中,通常意味着图表不是非常有效.

图表真正显示的唯一有用信息是颜色的年度变化.您可以在下面根据矩形高度进行着色.

但是+1用于找到另一种可视化数据的方法.

在此输入图像描述

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, at = 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)
for (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))))
}
Run Code Online (Sandbox Code Playgroud)

(我希望没人提交垃圾图表:{)

这里还有另一种非常简单的方法.应该先做这个,即创建样本数据,填充行,然后barplot处理其余的事情.但是,对这种方法的控制要少得多.

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述