How can I plot a histogram of a long-tailed data using R? -
i have data centered in small range (1-10) there significant number of points (say, 10%) in (10-1000). plot histogram data focus on (1-10) show (10-1000) data. log-scale th histogram.
yes, know means not bins of equal size
a simple hist(x)
gives while
hist(x,breaks=c(0,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,3,4,5,7.5,10,15,20,50,100,200,500,1000,10000)))
gives
none of want.
update following answers here produce want (i went continuous plot instead of bar-histogram):
breaks <- c(0,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,4,8) ggplot(t,aes(x)) + geom_histogram(colour="darkblue", size=1, fill="blue") + scale_x_log10('true size/predicted size', breaks = breaks, labels = breaks)![alt text][3]
problem i'd match between scale , actual bars plotted. there 2 options doing : 1 use actual margins of plotted bars (how?) "ugly" x-axis labels 1.1754,1.2985 etc. other, prefer, control actual bins margins used match breaks.
using ggplot2 seems easy option. if want more control on axes , breaks, can following :
edit : new code provided
x <- c(rexp(1000,0.5)+0.5,rexp(100,0.5)*100) breaks<- c(0,0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000,10000) major <- c(0.1,1,10,100,1000,10000) h <- hist(log10(x),plot=f) plot(h$mids,h$counts,type="n", xaxt="n", xlab="x",ylab="counts", main="histogram of x", bg="lightgrey" ) abline(v=log10(breaks),col="lightgrey",lty=2) abline(v=log10(major),col="lightgrey") abline(h=pretty(h$counts),col="lightgrey") plot(h,add=t,freq=t,col="blue") #position of ticks @ <- log10(breaks) #creation x axis axis(1,at=at,labels=10^at)
this close can ggplot2. putting background grey not straightforward, doable if define rectangle size of plot screen , put background grey.
check functions used, , ?par
. allow build own graphs. hope helps.
Comments
Post a Comment