Re: [R] Scientific notation in plots

From: McGehee, Robert <Robert.McGehee_at_geodecapital.com>
Date: Sat 14 Jan 2006 - 01:27:08 EST


You could also use a function like this to transform a number x into your "beautiful" notation, where x is the number and digits is the number of digits you would like to see after the decimal. Then you could use the axis and labels syntax suggested by Iain, as such:

sciNotation <- function(x, digits = 1) {

    if (length(x) > 1) {

        return(append(sciNotation(x[1]), sciNotation(x[-1])))     }
    if (!x) return(0)
    exponent <- floor(log10(x))
    base <- round(x / 10^exponent, digits)     as.expression(substitute(base %*% 10^exponent,

                        list(base = base, exponent = exponent))) }

plot(1:1000, axes = FALSE, type = "l", frame.plot = TRUE) axis(1, at = axTicks(1), label = sciNotation(axTicks(1), 1))

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of IAIN GALLAGHER Sent: Friday, January 13, 2006 8:09 AM
To: Oddmund Nordgård
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Scientific notation in plots

try something like this:

>axis(side=2, at=c(0, 5e+5, 1.5e+6, 2.5e+6),
labels=expression(0, 5%*%10^5, 1.5%*%10^6, 2.5%*%10^6)

it will place your 5e+5, 1.5e+6, 2.5e+6 as scientific notation at the correct positions on the y axis. the key is the "labels=expression...." part.

Cheers

iain

>
> Is it possible to use scientific notation of numbers
> on the axis of plots
> without using the xEy notation. That means: a
> beatiful 1x10^3 instead of 1E3.
> Logarithmic scale, in my case.
>
> Thank you very much!
>
> Oddmund
>
> ******************************************
>
> Oddmund Nordgrd
>
> Department of Haematology and Oncology
> Stavanger University Hospital
> P.O. Box 8100
> 4068 STAVANGER
> Phone: 51 51 89 34
> Email: nood@ext.sir.no
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jan 14 02:16:04 2006

This archive was generated by hypermail 2.1.8 : Sat 14 Jan 2006 - 06:07:52 EST