Skip to content
Back to formatted view

Raw Message

Message-ID: <4CF618EB.1020401@bitwrit.com.au>
Date: 2010-12-01T09:44:11Z
From: Jim Lemon
Subject: How to draw a rect() behind a hist() ?
In-Reply-To: <4CF5A46D.5010507@rampaginggeek.com>

On 12/01/2010 12:27 PM, Jason Edgecombe wrote:
> Hi,
>
> I have the following code:
>
> hist(gps$heartpercent, breaks=5)
> rect(90, par("usr")[3], 100, par("usr")[4], col = "red")
>
> How do I get the rectangle to appear behind the histogram. Barring that,
> how can I make certain bars of the histogram to be a certain color?
>
Hi Jason,
Does this do what you want?

heartpercent<-sample(0:100,200,TRUE)
library(plotrix)
barp(hist(heartpercent,breaks=5,plot=FALSE)$counts,
  names.arg=c("0-20","21-40","41-60","61-80","81-100"),
  do.first=rect(5,par("usr")[3],par("usr")[2],par("usr")[4],
  col = "red"))

Jim