[R] Changing x-axis values displayed on histogram

Sarah Goslee sarah.goslee at gmail.com
Tue Jul 10 21:59:52 CEST 2012


Hi,

Thanks for providing a small reproducible example.

You can disable the default axis and make your own custom version:

hist(histexample,breaks=bins, xaxt="n")
axis(1, at=seq(5.5, 15.5, by=2), labels=c("5-6", "7-8", "9-10",
"11-12", "13-14", "15-16"))

Sarah

On Tue, Jul 10, 2012 at 3:34 PM, jlwoodard <john.woodard at wayne.edu> wrote:
> Is it possible to change the x-axis values in a histogram to reflect binned
> values?
>
> Here are my data:
>
> histexample<-c(6,7,7,8,8,8,9,9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,12,12,12,12,13,13,13,14,14,14,15,16)
> hist(histexample)
>
> Now, I'll bin pairs of adjacent values together (e.g., 5-6, 7-8, 9-10,
> 11-12, 13-14, 15-16) using the following
>
> bins<-c(4.5,6.5,8.5,10.5,12.5,14.5,16.5)
> hist(histexample,breaks=bins)
>
> The displayed x-axis values are 6, 8, 10, 12, 14, and 16.  I'd like the
> x-axis values to reflect the values in each bin (e.g., 5-6, 7-8, 9-10,
> 11-12, 13-14, 15-16).  Any suggestions would be greatly appreciated!  Many
> thanks in advance.
>
> John
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list