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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With