Re: [R] How to draw a rect() behind a hist() ?

2010-12-01 Thread Jim Lemon

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

__
R-help@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.


Re: [R] How to draw a rect() behind a hist() ?

2010-12-01 Thread Ivan Calandra

Hi,
For your second question, take a look at ?clip. The example explains 
really well what you can do and how.

HTH,
Ivan


Le 12/1/2010 04:42, Peter Ehlers a écrit :

On 2010-11-30 17:27, 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?


Here are a couple of ways:
1. using hist(); just plot the histogram twice.

 x <- rnorm(1000, 100, 5)
 hist(x)
 rect(90, 0, 98, par('usr')[4], col = 'red')
 hist(x, add = TRUE)

For coloured bars, use a colour vector:

 hist(x, breaks = 5, col = c(3,3,4,4,2))

2. using lattice;

 histogram(x,
  panel=function(...){
panel.rect(90,0,98,1000,col='bisque',border=NA)
panel.histogram(...,col='transparent',lwd=2)
  }
 )

Again, you can define bar colours with a colour vector.
Lattice is more customizable albeit a little harder
to learn.

Peter Ehlers


Thanks,
Jason



__
R-help@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.



--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
R-help@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.


Re: [R] How to draw a rect() behind a hist() ?

2010-11-30 Thread Peter Ehlers

On 2010-11-30 17:27, 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?


Here are a couple of ways:
1. using hist(); just plot the histogram twice.

 x <- rnorm(1000, 100, 5)
 hist(x)
 rect(90, 0, 98, par('usr')[4], col = 'red')
 hist(x, add = TRUE)

For coloured bars, use a colour vector:

 hist(x, breaks = 5, col = c(3,3,4,4,2))

2. using lattice;

 histogram(x,
  panel=function(...){
panel.rect(90,0,98,1000,col='bisque',border=NA)
panel.histogram(...,col='transparent',lwd=2)
  }
 )

Again, you can define bar colours with a colour vector.
Lattice is more customizable albeit a little harder
to learn.

Peter Ehlers


Thanks,
Jason



__
R-help@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.