[R] value on logarithmic axis

David Carlson dcarlson at tamu.edu
Tue Feb 11 21:49:58 CET 2014


To prevent R from using scientific notation set the scipen
option and probably cex.axis to reduce the axis text or some of
the tick marks will be skipped:

options(scipen=10)
plot(x, y, pch=16, type="b", log="x", cex.axis=.8,
ylab=expression(bold("Y axis")),
     xlab=expression(bold("X axis")))

To specify the same labels you had originally, c(1, 10, 100,
1000) use

plot(x, y, pch=16, type="b",  log="x", xaxt="n",
ylab=expression(bold("Y axis")),
     xlab=expression(bold("X axis")))
xlim <- par("usr")[1:2]
lab.x <- seq(ceiling(xlim[1]), floor(xlim[2]))
axis(side=1, at=10^lab.x, lab=10^lab.x)

You can have more intervals, but you suggest 12, which would be
a very tight squeeze. For example to get 7 labels c(1, 3.2, 10,
31.6, 100, 316.2, 1000):

plot(x, y, pch=16, type="b",  log="x", xaxt="n",
ylab=expression(bold("Y axis")),
     xlab=expression(bold("X axis")))
xlim <- par("usr")[1:2]
lab.x <- seq(ceiling(xlim[1]), floor(xlim[2]), by=.5)
axis(side=1, at=10^lab.x, lab=round(10^lab.x, 1))

David C

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Luigi
Marongiu
Sent: Tuesday, February 11, 2014 11:52 AM
To: r-help at r-project.org
Subject: [R] value on logarithmic axis

dear all,
I have a xy plot in which x is logarithmic. The plot is fine,
and I can
also represent the logarithimic axis usign a tip given me by
William
Dunlap. However I would like to plot the actual x value rather
than the
log10 s in this case. If I remove the xaxt="n" the plot reports
the
scientific notation of the log, a rough version of the nice
notation
written by William Dunlap.
So how can I write the value of the x axis?

################################################################
############

y<-c(25.84, 26.84, 27.85, 28.86, 29.86, 30.87, 31.88, 32.88,
33.89,
34.90, 35.90, 36.91)
x<- c(1000, 500,  250,  125,  62.50,  31.25,  15.63,  7.81,
3.91,  1.95,
 0.98,  0.49)

plot(x, y, pch=16, type="b",  log="x", xaxt="n",
ylab=expression(bold("Y
axis")), xlab=expression(bold("X axis")))

 xlim <- par("usr")[1:2]
 lab.x <- seq(ceiling(xlim[1]), floor(xlim[2]))
 axis(side=1, at=10^lab.x, lab=as.expression(lapply(lab.x,
function(x)bquote(10^.(x)))))

################################################################
###########

Thank you very much,
Luigi

PS probably the x axis values should have the form:
x.axis<-c(0.49, 0.98, 1.95, 3.91, 7.81, 15.63, 31.25, 62.50,
125, 250, 500,
1000)

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible
code.




More information about the R-help mailing list