计数的彩色条状图

时间:2011-10-15 04:14:02

标签: r graphics plot

我在R中创建一个条形图,并希望按条形高度(计数)

为每个条形图着色

目前我所拥有的:

z=rnorm(n,1)
Z=runif(n)
h=barplot(Z)

我有照片,但没有足够的声誉发布它们。 所以这是MatLab中的示例: MatLab-Color bars by height

2 个答案:

答案 0 :(得分:7)

除了baptiste的ggplot2解决方案,这是一个使用barplot的简单示例:

Z <- sample(20,15,replace = TRUE)
barplot(Z,col = heat.colors(max(Z))[Z])

产生类似这样的东西:

enter image description here

答案 1 :(得分:5)

试试这个,

library(ggplot2)
d = data.frame(x = rnorm(100))
ggplot(d) + geom_bar(aes(x, fill = ..count..))