[R] Drawing a histogram from a massive dataset

Kyaw Sint (Joe) kyaw.sint at yale.edu
Fri Jul 15 17:17:35 CEST 2011


Hello,

I assume you have imported the dataset. You can use the hist from the
graphics package from the main R program. A tricky part is that the
freq=TRUE (the default) plots frequencies and freq=FALSE plots probability
densities, not percent of the histogram cells. You can sum the counts and
calculate the percent before plotting.

	hist1<-hist(varname, plot=FALSE)
	sum <- sum(hist1$counts)
	hist1$counts <- hist1$counts/sum*100
	plot(hist1, main=paste("Histogram of",deparse(substitute(varname))),
	xlab=deparse(substitute(varname)), ylab="Percent",
	)

Also, if you are new to R, there are very useful manuals and guides at
http://cran.r-project.org/manuals.html . You can look up documention in R,
such as ?hist command for documentation for hist function. 

Regards,
Kyaw Sint (Joe) 


> Dear All,
> 
> I have a massive dataset from which I would like to draw a histogram.
> Any ideas on how to accomplish this?
> 
> Thanks in advance,
>
> Paul



More information about the R-help mailing list