colour bins of histogram in R
问题 I want to plot a barplot like in figure. I want each bin to be coloured based on the sum of the value in the other columns. . I made a reproducible example here. library(reshape) library(ggplot2) values= replicate(4, diff(c(0, sort(runif(92)), 1))) colnames(values) = c("A","B","C","D") counts = sample(10:100, 93, replace=T) df = data.frame(cbind(values,"count"=counts)) mdf = melt(df,id="count") mdf = mdf %>% mutate(binCounts = cut(count, breaks = seq(0, 100, by = 5))) plot = ggplot(mdf) +