0
votes

I have bar plot realize with R and I would like to color the bars with different colors depending on the value of the x-axis. For example I would assign for for the bar with x = 1 the color orange, for the bar with x = 2 the color yellow, for the bars 3=<x=<5 the color light green and for the bars from 6 to 28 the color dark green. How do I enter this condition?

1

1 Answers

0
votes

You can assign colors to the bars via the color parameter of the barplot() function. The argument takes either a single color (if you want all bars to look the same) or a vector of colors.

In your case, given the data stored in a matrix m, you would write:

barplot(m,color=c("orange","yellow",rep("lightgreen",3),rep("darkgreen",23)))