[R] Histogram for factors
Robert Gentleman
rgentlem at jimmy.harvard.edu
Sat Jan 13 15:46:08 CET 2001
On Sat, Jan 13, 2001 at 10:31:16AM +0100, Martin Maechler wrote:
> >>>>> "PD" == Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
>
> PD> Thomas Vogels <tov at ece.cmu.edu> writes:
> >> Hi,
> >>
> >> I keep running into this:
> R> hist (f)
> >> Error in hist.default(f) : `x' must be numeric
> >>
> >> To which of course something like (simplified but not beyond
> >> repair):
> R> hist.factor <- function (ff) {
> >> jj <- table (ff) jb <- barplot (jj, ylab="Frequency",
> >> xlab=deparse(substitute(ff))) axis (1, jb, names (jj)) }
> R> hist (f)
> >> is a possible solution.
> >>
> >> Why is a 'hist.factor' not part of the base distribution? Is this
> >> kind of thing discouraged? Usually not needed? Am I missing sth
> >> else?
>
> PD> Well histograms are density estimates defined for continuous
> PD> variables. What you're drawing is a barplot. barplot.factor might
> PD> be a good idea, though.
>
> Well,
> plot(f)
> already draws a barplot of a factor f (by the plot.factor method).
Which many of us would think of as being the right "default" plot
for a factor. However, I also think that the right thing for histogram
to do is to inform you that this is not a continuous variable.
I don't think of a barplot (barchart) as a specialized histogram.
>
> Martin
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
+---------------------------------------------------------------------------+
| Robert Gentleman phone : (617) 632-5250 |
| Associate Professor fax: (617) 632-2444 |
| Department of Biostatistics office: M1B28
| Harvard School of Public Health email: rgentlem at jimmy.dfci.harvard.edu |
+---------------------------------------------------------------------------+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list