0

I am trying to plot a simple bar.plot where heat.colors reflect increasing (red) or decreasing (blue or yellow) trends (through time in this case).

For example,

set.seed(1)
estimates<-sample(1:100, 30, replace=FALSE) #this estimates are not sorted
barplot(estimates, cex.names=0.8, col=heat.colors(30, alpha = 1))

Barplot with heat-colors

However, in this case, colors do not reflect the changing estimates but only the direction of X axis values.

Any ideas?

user3660245
  • 123
  • 1
  • 7

1 Answers1

1

I am unsure of what you would like to achieve, but I think you want the colours to reflect the hight of the bars in this example. In that case, you should use the rank of the estimates to extract the right colour. So in summary:

set.seed(1)
estimates <- sample(1:100, 30, replace=FALSE) #this estimates are not sorted

colors <- heat.colors(30, alpha = 1)
ordered_colors <- colors[rank(estimates)] # or 31-rank(estimates)

barplot(estimates, cex.names=0.8, col=ordered_colors)
van Nijnatten
  • 404
  • 5
  • 15