我正在R中创建一个条形图,并希望按条形高度(计数)为每个条形图着色
目前我所拥有的:
z=rnorm(n,1)
Z=runif(n)
h=barplot(Z)
Run Code Online (Sandbox Code Playgroud)
我有照片,但没有足够的声誉发布它们.所以这是MatLab中的示例: MatLab-Color条形图的高度
除了baptiste的ggplot2解决方案之外,这里还有一个简单的例子barplot
:
Z <- sample(20,15,replace = TRUE)
barplot(Z,col = heat.colors(max(Z))[Z])
Run Code Online (Sandbox Code Playgroud)
产生这样的东西:
试试这个,
library(ggplot2)
d = data.frame(x = rnorm(100))
ggplot(d) + geom_bar(aes(x, fill = ..count..))
Run Code Online (Sandbox Code Playgroud)