2011-10-15 160 views
5

我創造了R A barplot和想要的顏色由杆高度各條(計數)顏色Barplot伯爵

目前我有:

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

我有照片,但沒有足夠的聲譽張貼他們。 因此,這裏是MATLAB中的例子: MatLab-Color bars by height

+0

錯誤:找不到函數「rand」 – TMS

+0

對不起rand是matlab代碼。我想我用過rnorm – crock1255

回答

4

試試這個,

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

喜歡它。謝謝! – crock1255

6

除巴蒂斯特的GGPLOT2解決方案,這是一個使用barplot一個簡單的例子:

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

產生類似這個:

enter image description here

+0

這太好了。非常感謝! – crock1255