Skip to content

Is ther a possibility to display the log(frequency) instead of the frequency in the hist plot?

8 messages · Uwe Ligges, Wolski, Peter Kleiweg +2 more

#
Is there a possibility to display the log(frequency) instead of the
frequency in the hist?
--
Witold Eryk Wolski
Max Plank Institut fuer Molekulare Genetik
Ihnestr73 14195 Berlin
Germany
tel.:
Work 0049-30-84131426
http://www.molgen.mpg.de/~wolski


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Witold Eryk Wolski wrote:
I think you want something like the following example:

 x <- runif(100) * 10
 my.hist <- hist(x)
 my.hist   # have a look at the values!
 my.hist$counts <- log(my.hist$counts, 10)  # logarithm with base 10
 plot(my.hist)  # now plot it again with log(frequency)


Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Uwe Ligges wrote:

            
Hi Uwe!
First thanks for your answer.
Some questions still remain to me.
1. How take an log if one of the my.hist$counts equals 0?
2. You code expample produces an error message which i doesnt understand.
Error in plot.window(xlim, ylim, log, asp, ...) :
        invalid xlim
3. I tried as workaround something similar.
plot(my.hist$mids,log(my.hist$counts),type="s") And this would work quite good for
my needs.
But problem with log(0) = -Inf still remains.

I think I have to formulate my question more general. Why, and this is an question
which I am asking myself since
I am started using  R becouse im using the hist plot quite often,  the hist plot in
the base package has no similar
options like eg. the histogram plot in XMGR?


THX
Eryk
--
Witold Eryk Wolski
Max Plank Institut fuer Molekulare Genetik
Ihnestr73 14195 Berlin
Germany
tel.:
Work 0049-30-84131426
http://www.molgen.mpg.de/~wolski


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Witold Eryk Wolski wrote:
You want to use a histogram, so you have to think about what you want to
do in that case.
??? 
No, cannot reproduce it with my example!
So we have to change the mathematical axioms. ;-)
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Witold Eryk Wolski skriver...
log(my.hist$counts + 1)
#
On Thu, 18 Jan 2001, Witold Eryk Wolski wrote:

            
You could try log10(my.hist$counts+1), which is a standard transformation
in ecology.
I don't get it here either.  Are you doing _exactly_ what Uwe suggested
above?  Or are you doing the histogram etc. on your own data (rather than
a sample from runif())?  What is the range of your data?
What are those options?

  The general answers to the questions "why doesn't R have ... ?" are
usually:

  1. it would be a useful feature, but no-one has thought of/suggested it
yet (?);
  2. ditto, but no-one has had the time or energy or specific knowledge
required to code it (e.g. full integration of 3D graphics, GAM);
  3. it represents something that at least some people (the R Core team,
who tend to be awfully knowledgeable about statistical and graphical
issues) think is a bad idea (e.g. type III sums of squares);
  4. it is minor enough, or there is an easy enough way to work around it,
that spending time on it/"bloating" R with it doesn't seem worthwhile.

  Ben

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I imagine that the point of logging the histogram count axis is just for
displaying purposes, and your suggestion would alter the scale.  I find it
easier to just leave the 0 counts as zero.

hist(my.data, plot=F)$counts -> my.hist.counts;
my.hist.counts[my.hist.counts != 0] <- 
                      log(my.hist.counts[my.hist.counts!= 0]);
plot(my.hist.counts, type="hist");


-Alex Morgan

Phone: 781-271-6306                       "They laughed at Newton.
Office: 3K-136                            They laughed at Einstein.
AOL Instant Messenger: HomeySage          But they also laughed at Groucho
                                          Marx."
                                                      --Carl Sagan
On Thu, 18 Jan 2001, Peter Kleiweg wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
The only potential problem with this solution is that bins with zero
counts and bins with 1 count will both be treated as zeros.

  Consider:

my.data <- c(1.5,1.5,2.5,4.5,5.5,5.5)
my.hist.counts <- hist(my.data, plot=F, breaks=0:6)$counts

etc.

  This is an unlikely event with the default "breaks" settings,
though.  (On the other hand, the fact that you have bins with zero counts
says that you might well have bins with only 1 count.)

  Ben
On Thu, 18 Jan 2001, Alexander A. Morgan wrote: