# [R] Histogram with different colors for different portions

From: <arnholtat_at_appstate.edu>
Date: Sun, 30 Dec 2007 17:57:38 GMT

Dear Rusers,
I would like to color different sections of a histogram different colors. I have an example that was done by "brute force" given below. Has anyone implemented something like this in general? If not, any suggestions/pointers on how to write a general function to do so would be most appreciated. Alan-
################################################################################
set.seed(13)
nnum <- rnorm(1000, 100, 10)
xbar <- mean(nnum)
SD <- sd(nnum)
BR <- seq(xbar - 4*SD, xbar + 4*SD, by = .25*SD)
# Histogram showing xbar +- sd in different colors
hist(nnum, breaks=BR, col=c(rep("red", 8), rep("blue", 4),

rep("pink", 8), rep("blue", 4), rep("red", 8)))
################################################################################
# Histogram depicting Hinge Spread with boxplot
layout(matrix(c(1, 2)), heights=c(2, 1))

```fn <- fivenum(nnum)
LH <- fn[2]
UH <- fn[4]
HS <- UH - LH
```

SHS <- HS/10
BR <- seq(LH - SHS*30, UH + SHS*30, SHS) par(mar=c(0,2,3,2))
hist(nnum, breaks=BR, col=c(rep("red", 30), rep("blue", 10),
```     rep("red", 30)), xlim=c(60,140), axes=FALSE, xlab="",
ylab="", main="")
```

#

par(mar=c(3,2,0,2))
boxplot(nnum, col="blue", horizontal=TRUE, ylim=c(60, 140), axes=FALSE) axis(side=1)

Alan T. Arnholt
Professor and Assistant Chair
Department of Mathematical Sciences
Appalachian State University
T:(828)262-2863
F:(828)265-8617
http://www1.appstate.edu/~arnholta/

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 30 Dec 2007 - 18:00:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Dec 2007 - 18:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.