[R] Histogram

David Barron mothsailor at googlemail.com
Tue Jun 19 18:23:03 CEST 2007


I expect there's a more elegant way of doing this, but this should work:

set.seed(101)
x <- rnorm(500,sd=.03)
hist (x, seq(-0.1,0.1,0.01),freq = FALSE)
d <- density(x,bw="SJ")
lowt <- d$x < -.05
upt <- d$x > .05
lines (d$x[lowt],d$y[lowt], col = "red")
lines(d$x[upt],d$y[upt], col = "red")


On 19/06/07, livia <yn19832 at msn.com> wrote:
>
> Hello, I am using the following codes to plot a histogram and density line
> for x. For the density line, I just want it to show the two tails, eg, for x
> larger than 0.05 ans smaller than -0.05
>
> hist (x, seq(-0.1,0.1,0.01),freq = FALSE)
> lines (density(x,bw="SJ"), x> 0.05 & x< (-0.05), col = "red")
>
> But is does not work, can anyone give me some advice?
>
>
>
> --
> View this message in context: http://www.nabble.com/Histogram-tf3947281.html#a11197644
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP



More information about the R-help mailing list