简体   繁体   English

如何在R中创建比例区域堆积的条形图?

[英]How can I create a proportional area stacked bar chart in R?

I would like to create a horizontal proportional stacked bar "chart", using R. 我想使用R创建水平比例堆叠的条形图“图表”。

My data is unidimensional. 我的数据是一维的。 It represents failure rates in successive categories, and looks like this: 它代表连续类别中的失败率,如下所示:

taskC=c(16, 10, 13, 5, 4, 5, 12)
labels=c("All correct", "1 fail", "2 fails", "3 fails", "4 fails", "5 fails", "All fail")

I would like to create something along the lines of the chart at the below URL, though using a different colour graident (topo is fine) and having it horizontal instead of vertical. 我想沿着下面的URL在图表的各行中创建一些内容,尽管使用不同的颜色(topo很好)并使它水平而不是垂直。

http://www.improving-visualisation.org/vis/id=70 http://www.improving-visualisation.org/vis/id=70

I've looked through ggplot and VCD and can't find anything that solves this. 我浏览了ggplot和VCD,找不到解决此问题的方法。 A 3d graph would be ideal, though not critical. 3d图形将是理想的,尽管并不重要。 Although the data can be represented using a pie chart, these don't provide the linear sense of proportion I want, and also don't sufficiently capture the ordinal nature of the data. 尽管可以使用饼图来表示数据,但这些不能提供我想要的线性比例感,也不能充分捕捉数据的序数性质。

You can simply do: 您可以简单地执行以下操作:

barplot(as.matrix(taskC), horiz=TRUE, col=rainbow(7), xaxt="n")
axis(1, labels=labels, at=cumsum(taskC)-(taskC/2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM