Skip to content
Prev 4068 / 63424 Next

Modified Histogram functions

Dear all,

I have done further modifications on the histogram functions that I
reported earlier this year, and I hope this can be of use and perhaps
included in the distribution. I have been using this stuff a couple of
months myself, and while it is nothing sophisticated, it has it's
applications. :-) I did a few small modifications today to make it a bit
more compact.

I have modified the hist.default() function so that the list it returns
has class "histogram". I have put the plotting in a separate function,
plot.histogram(), which is called from hist.default if plot=T, and I have
made a lines.histogram() (calling it "lines", is that a wise choice? It
seemed most natural, but then again....), which can be used to overlay
histograms on existing histograms. Here it is obviously a lot of room for
improvement. E.g. calling plot.histogram() with multiple histogram
objects could produce a plot where coloumns representing the same values
are grouped, I haven't addressed that. The code is below my .sig.

As you can see, there are few changes from your code. The biggest change
is that hist.default() calls plot.histogram() (or rather plot()). Also
note that the warning about wrong areas only appears in hist.default(). I
figured that the user is most likely created the histogram object with
hist, so s/he might no want to be bothered with this warning again. I
don't know if this is wise, s/he might just have forgotten or something. :-)

I guess plot.histogram() may also be made more compact by calling
lines.histogram() to plot the actual rects, but I didn't find a practical
way of doing this, so I didn't... :-) And, contrary to
the other functions making histogram plots, lines.histogram() does take
lty as an argument (useful for making dotted borders, to separate one
histogram from another, particulary useful when using colors).

I've got a function for adding two similar histograms as well, but that's
so hacked up I guess it isn't worth much.

BTW, I found a typo in the help for rect:
     xpd: logical (``expand''); if `FLASE', everything is clipped to
          the plot region.

Hope this is useful for someone... :-)

Best,

Kjetil