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 Nordg??rd Department of Haematology and Oncology Stavanger University Hospital P.O. Box 8100 4068 STAVANGER Phone: 51 51 89 34 Email: nood at ext.sir.no
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 --- Oddmund Nordg????rd <nood at ext.sir.no> wrote:> > 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 Nordg??rd > > Department of Haematology and Oncology > Stavanger University Hospital > P.O. Box 8100 > 4068 STAVANGER > Phone: 51 51 89 34 > Email: nood at ext.sir.no > > ______________________________________________ > R-help at 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 >
Just what I needed! Thank you very much! Oddmund On Fri, 13 Jan 2006, IAIN GALLAGHER wrote:> 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 > > --- Oddmund Nordg????rd <nood at ext.sir.no> wrote: > > > > > 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 Nordg??rd > > > > Department of Haematology and Oncology > > Stavanger University Hospital > > P.O. Box 8100 > > 4068 STAVANGER > > Phone: 51 51 89 34 > > Email: nood at ext.sir.no > > > > ______________________________________________ > > R-help at 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 > > >
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 at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of IAIN GALLAGHER Sent: Friday, January 13, 2006 8:09 AM To: Oddmund Nordg????rd Cc: r-help at 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 --- Oddmund Nordg????rd <nood at ext.sir.no> wrote:> > 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 Nordg??rd > > Department of Haematology and Oncology > Stavanger University Hospital > P.O. Box 8100 > 4068 STAVANGER > Phone: 51 51 89 34 > Email: nood at ext.sir.no > > ______________________________________________ > R-help at 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 at 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
You could also write your numbers using SI suffixes. Below is a function I use for this purpose. The option "near" allows you to require that numbers between 0.001 and 1000 are written as decimal; i.e. "0.010" appears as "0.010" instead of "10.0m". ## ## num2SI converts numbers to SI suffixed numbers ## num2SI<-function(num,digits=4,near=TRUE){ power<-signif(log10(abs(num)),digits=6) power3=floor(power/3); power3[!is.finite(power3)]=0 powers=c("y","z","a","f","p","n","u","m","","k","M","G","T","P") powerstr=powers[power3+9] newnum=signif(num/10^(power3*3),digits=digits) newnum[is.nan(newnum)]=0 numstr=(paste(newnum,powerstr,sep="")) nearidx=near & (abs(num)>0.001) & (abs(num)<1000) nearidx[is.na(nearidx)]=FALSE if(sum(nearidx)) numstr[nearidx]=sprintf("%.*f",pmax(1,(digits-floor(power[nearidx])-1),na.rm=TRUE),num[nearidx]) numstr[!is.finite(num)] = paste(num[!is.finite(num)]) return(numstr) } Leif Kirschenbaum Senior Yield Engineer Reflectivity, Inc. (408) 737-8100 x307 leif at reflectivity.com> Message: 6 > Date: Fri, 13 Jan 2006 12:49:54 +0100 (CET) > From: Oddmund Nordg??rd <nood at ext.sir.no> > Subject: [R] Scientific notation in plots > To: r-help at stat.math.ethz.ch > Message-ID: <Pine.LNX.4.56.0601131247300.25418 at dna.sir.no> > Content-Type: TEXT/PLAIN; charset=ISO-8859-1 > > > 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 Nordg?rd > > Department of Haematology and Oncology > Stavanger University Hospital > P.O. Box 8100 > 4068 STAVANGER > Phone: 51 51 89 34 > Email: nood at ext.sir.no