Hist

I find myself always rewriting this code, so instead I will post it.

It is code to make a solid histogram with a thick outline, which is useful to overlay two empirical distributions or if you want to change the x axis to log for example.

x = rnorm(1000)
h = hist(x,breaks=20,plot=FALSE)
brks = rep(h$breaks,each=2)
counts = c(0,rep(h$counts,each=2),0)
plot(brks,counts,type="n",xlab="Value",ylab="Frequency",main="Histogram")
lines(brks,counts,lwd=2)
polygon(brks,counts,col=rgb(1,1,0,.5))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s