Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color Barplot by Count

Tags:

plot

r

graphics

I am creating a barplot in R and want to color each bar by bar height (count)

Currently what I have:

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

I have pictures but not enough reputation to post them. So here is the example in MatLab: MatLab-Color bars by height

like image 748
crock1255 Avatar asked Oct 15 '11 04:10

crock1255


1 Answers

In addition to baptiste's ggplot2 solution, here's a simple example using barplot:

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

which produces something like this:

enter image description here

like image 150
joran Avatar answered Sep 30 '22 08:09

joran