Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22693

How to colour histogram according to quantile range?

$
0
0

I want to colour my histogram plot to show the quantile range distribution but I am unable to figure out where/how to add the colours into my code.

Here is my sample data and code (using iris dataset).# Get summary info and quantile range info for datasummary(iris)vals<- c(q1=quantile(iris$Sepal.Length, .25),          q2=quantile(iris$Sepal.Length, .50),          q3=quantile(iris$Sepal.Length, .75))# Create histogram and colour bins according to quantile range; add mean/med linesh <- ggplot(iris, aes(Sepal.Length), fill=vals) +  geom_histogram(color="black", bins=5) +  scale_x_continuous(breaks=seq(0, 10, 2)) +  scale_y_continuous(expand=c(0,0), limits=c(0,60)) + theme_bw() +  labs(x="Length", y="Frequency") +  theme(axis.title.x = element_text(size=12),        axis.text.x = element_text(size=12),        axis.title.y = element_text(size=12),        axis.text.y = element_text(size=12))h + geom_vline(xintercept = median(iris$Sepal.Length),col="red", size=1.1, lty="solid") +  geom_vline(xintercept = mean(iris$Sepal.Length),col="blue", size=1.1, lty="solid")

I've tried several attempts of changing the "fill" function in different parts of ggplot(aes) and in geom_hist() but the resulting figure always comes up dark grey or doesn't work.

I just want to colour the bins to show the quantile range, so 4 colours on the figure total.


Viewing all articles
Browse latest Browse all 22693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>