[R] breaks display of hist
Rui Barradas
rui1174 at sapo.pt
Tue Feb 21 17:11:51 CET 2012
Hello,
carol white wrote
>
> Hello,
> How can I display the xlim of the boundaries of all or specific breaks in
> a histogram? I generated the attached plot with hist and would like to
> know which values of x correspond to the frequency 329 and display these
> values on the x axis?
>
> Best,
>
> carol
> ______________________________________________
> R-help@ 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.
>
Maybe I'm making a confusion with your 'breaks' and 'frequency 329' so here
go both:
dev.new()
h <- hist(x)
# This plots the values of 'x' in the bin with freq 21
# (There's no freq 329 in this vector 'x')
b.lower <- which(h$breaks == h$breaks[h$counts == 21])
x.lower <- h$breaks[b.lower]
x.upper <- h$breaks[b.lower + 1]
rug(x[x > x.lower & x <= x.upper])
dev.new()
h <- hist(x, axes=FALSE)
axis(1, at=h$breaks)
axis(2, at=pretty(h$counts))
# This plots the values of 'x' in the bin (329, 329.5]
# (Starting at break 329, left open, right closed, see '?hist')
b.lower <- which(h$breaks == 329)
x.lower <- h$breaks[b.lower]
x.upper <- h$breaks[b.lower + 1]
rug(x[x > x.lower & x <= x.upper])
If you don't want a rug, maybe you could try adding the following to the
previous graph
points(x[x > x.lower & x <= x.upper], 1:h$counts[b.lower])
Or maybe a combination of some of the above. See the return value of
?hist
and ?axis, ?rug, ?points, ?par.
Hope this helps,
Rui Barradas
--
View this message in context: http://r.789695.n4.nabble.com/breaks-display-of-hist-tp4406966p4407457.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list