[R] value on logarithmic axis

David Carlson dcarlson at tamu.edu
Wed Feb 12 16:47:08 CET 2014


If you want specific values (e.g. the values of the x points),
just use those as the at= and lab= arguments to axis():

plot(x, y, pch=16, type="b",  log="x", xaxt="n", 
     ylab=expression(bold("Y axis")), xlab=expression(bold("X
axis")))
axis(side=1, at=x, lab=x, cex.axis=.85)

David C

From: Luigi Marongiu [mailto:marongiu.luigi at gmail.com] 
Sent: Wednesday, February 12, 2014 4:59 AM
To: dcarlson at tamu.edu
Subject: Re: [R] value on logarithmic axis

Dear David,
thank you for your indication. I see that the scale is
determined by the call "by=" within the seq function, and in
fact I can change the number of elements by modifying the number
fed into the function; so with 0.25 I obtain 14 elements. But
what if I want to use exactly the value I indicated (which
correponds to the different point)?
In addition, using by=0.25 etc the count starts at 1 and does
not cover 0.98 and 0.49. How can I set the count at zero?
Best regards
Luigi
 

On Tue, Feb 11, 2014 at 8:49 PM, David Carlson
<dcarlson at tamu.edu> wrote:
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