I have a dataframe in R with three columns, label
indicates the x-axis label, values
would indicate the bar height for a barplot, and and a color
value. For instance:
label value color
1 Label1 0.9645477 0.434680035
2 Label2 1.0816859 0.070992644
3 Label3 1.0043559 0.923586653
4 Label4 1.0065987 0.884469520
5 Label5 NA NA
6 Label6 0.9537397 0.307786218
I'd like to make a bar plot of the values where the bars are colored by the value in the color column. The color column always ranges from 0 to 1 and I'd like to make discrete colors, on a green to red spectrum, for bins 0-0.05, 0-0.1, etc.
And then I'd like to have a legend associated with the barplot. For the cases of NA, I'd like there to just be an empty spot on the plot with no bar.
How would I do this?