# [R] Visualization of histograms

(Ted Harding) ted.harding at wlandres.net
Mon Nov 8 14:34:13 CET 2010

```On 08-Nov-10 12:56:26, Etienne Stockhausen wrote:
> Dear r-user,
> I've wrote a small function to visualize the creation of a histogram.
> Therefore I create a vector with random values and let them plot in
> histograms. I better give a small example in R-Code:
>
> i=0
> funVec=rnorm(1000)
> temp=hist(funVec,plot=FALSE)
>
> plot(1,xlim=c(max(temp\$breaks),min(temp\$breaks)),
>      ylim=c(0,max(temp\$counts)+0.1*max(temp\$counts)),col="white")
> for(i in 1:1000)
>  {
>  Sys.sleep(1/25)
>  }
>
> I don't find any mistake in the example above and nevertheless there
> something strange about the result. R should plot 1000 histograms
> with time breaks of 1/25 seconds between the single plots. But the
> program visualize not even 100 steps. I don't understand that
> circumstance. If I don't use the add parameter, R visualize all 1000
> steps.
>
> I hope somebody could help me or explain me what ist happening there.
> I m looking forward to any hints or clues.
>
> Greetings and thanks in advance
> Etienne

I tried your code, and observed what you expected to see (not what
you say you saw). It may be a problem with your system. As a check,

i=0
funVec=rnorm(1000)
temp=hist(funVec,plot=FALSE)

plot(1,xlim=c(max(temp\$breaks),min(temp\$breaks)),
ylim=c(0,max(temp\$counts)+0.1*max(temp\$counts)),col="white")
maxx<-max(temp\$breaks) ; maxy<-max(temp\$counts) ## upper x & y lims
for(i in 1:1000)
{
points(i*maxx/1000,i*maxy/1000,pch="+")  ## plot a "tracker" point
Sys.sleep(1/25)
}

and saw the "tracker" move steadily from start to finish, with
clearly far more than a mere 100 steps, and at each new tracker
point there is also a change in the histogram. So in my case the
results were plotted as you wanted.

My system:

sessionInfo()
R version 2.11.0 (2010-04-22)
i486-pc-linux-gnu

locale:
[1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=C              LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.11.0

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 08-Nov-10                                       Time: 13:34:10
------------------------------ XFMail ------------------------------

```