So far, I’ve managed to change the colour a single bar in a histogram following the example here
test <- rnorm(100);
h <- hist(test);
b <- cut(1, h$breaks);
clr <- rep("grey", length(h$counts));
clr[b] <- "red";
plot(h, col=clr);
I want to be able to change the colour of histogram bins that are above a certain x-axis value – e.g. that are above 1 in the distribution function in the example. Part of the reason why I am having trouble is that I don’t exactly understand the factor that cut() returns.
Fundamentally you want a logical selector on
testnot on thecuts.Here’s what your cut object looks like:
The levels are of type character:
The data is of type numeric:
Here’s a solution using ggplot2 rather than making the cuts and so forth by hand: