Re: [R] Logarithmic axis -- now in new version of 'sfsmisc'

2007-11-21 Thread Martin Maechler
 GaGr == Gabor Grothendieck [EMAIL PROTECTED]
 on Tue, 20 Nov 2007 13:35:34 -0500 writes:

GaGr See:
GaGr http://finzi.psych.upenn.edu/R/Rhelp02a/archive/57255.html

Also, incidentally several weeks ago, I had added the following
to the 'ChangeLog' of my package  sfsmisc :

2007-10-13  Martin Maechler  [EMAIL PROTECTED]

* R/prettylab.R (eaxis): new function for nice (log) axis
labeling. (pretty10exp): drop.1: -10^k instead of -1*10^k

Here is the code -- which also needs package sfsmisc.

eaxis - function(side, at = axTicks(side, log=log), labels = NULL, log = NULL,
  f.smalltcl = 3/5, at.small = NULL, small.mult = NULL,
  outer.at = TRUE, drop.1 = TRUE)
{
## Purpose: Extended, Engineer-like (log-)axis
## --
## Author: Martin Maechler, Date: 13 Oct 2007

 stopifnot(require(sfsmisc)) ## --- just for the post to R-help

is.x - side%%2 == 1
if(is.null(log)) {
XY - function(ch) paste(if (is.x) x else y, ch, sep = )
log - par(XY(log))
}
## use expression (i.e. plotmath) if 'log' or exponential format:
use.expr - log || format.info(as.numeric(at), digits=7)[3]  0
if(is.null(labels))
labels - if(use.expr) pretty10exp(at, drop.1=drop.1) else TRUE
else if(is.na(labels)) # no 'plotmath'
labels - TRUE
axis(side, at = at, labels = labels)
if(is.null(at.small)) { ## create smart default, using small.mult
at.small -
if(log) {
if(is.null(small.mult)) small.mult - 9
at. - at[log10(at) %% 1  1e-3] ##  the 10^k ones:
if(length(at.))
outer(2:small.mult, c(if(outer.at) at.[1]/10, at.))
} else {
## assumes that 'at' is equidistant
d - diff(at - sort(at))
if(any(abs(diff(d))  1e-3 * (dd - mean(d
stop('at' is not equidistant)
if(is.null(small.mult)) {
## look at 'dd' , e.g. in {5, 50, 0.05, 0.02 ..}
d. - dd / 10^floor(log10(dd))
small.mult - {
if(d. %% 5 == 0) 5
else if(d. %% 4 == 0) 4
else if(d. %% 2 == 0) 2
else if(d. %% 3 == 0) 3
else if(d. %% 0.5 == 0) 5
else 2 }
}
outer(1:(small.mult-1)/small.mult * dd,
  c(if(outer.at) at[1]-dd, at), +)
}
##
if(outer.at) { # make sure 'at.small' remain inside usr
p.u - sort(par(usr)[if(is.x) 1:2 else 3:4])
if(log) p.u - 10^p.u
at.small - at.small[p.u[1] = at.small  at.small = p.u[2]]
}
}
axis(side, at = at.small, label = FALSE,
 tcl = f.smalltcl * par(tcl))
}

A few example calls [ from  example(eaxis)  once you've got the
  new version of package 'sfsmisc' ]:

x - lseq(1e-10, 0.1, length = 201)
plot(x, pt(x, df=3), type = l, xaxt = n, log = x)
eaxis(1)

## If you like the ticks, but prefer traditional (non-plotmath) labels:
plot(x,  gamma(x),   type = l, log = x)
eaxis(1, labels=NA)

x - lseq(.001, 0.1, length = 1000)
plot(x, sin(1/x)*x, type = l, xaxt = n, log = x)
eaxis(1)

## non- log-scale : draw small ticks, but no 10^k if not needed:
x - seq(-100, 100, length = 1000)
plot(x, sin(x)/x, type = l, xaxt = n)
eaxis(1)



Given the interest, I've now made sfsmisc ready for the next
release, version 0.96-01  
and uploaded that to CRAN.
Feedback is highly appreciated.

The unpatient can it also get from 
ftp://ftp.stat.math.ethz.ch/U/maechler/R/
both as source (*.tar.gz)  or Windows-binary package (*.zip).




GaGr On Nov 20, 2007 1:21 PM, John Wiedenhoeft [EMAIL PROTECTED] wrote:
 Hi there,
 
 I guess this must be a standard issue, but I'm starting to go crazy with 
it. I
 simply want a plot with the x axis being logarithmic, having labels 1, 
10,
 100..., and ten unlabelled ticks between each of them - just as they
 introduce logarithmic axis at school. I've played around a bit with 
log=x,
 xlog=T (where exactly is the difference here?), xaxp, and xaxt 
(unfortunately
 xaxt=l isn't implemented). The best I get is a plot with an axis 
having a
 single 100 and nothing else...
 
 here is what I've tried:
 
 pdf(file=kennlinien.pdf);
 par(log=x, xlog=TRUE);
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 #plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, kennlinie2)),
 xlim=c(0, max(reizstaerke)), log=x, xlog=TRUE, xaxp=c(1, 2, 1), 
type=b);
 #plot(reizstaerke, kennlinie1, type=b, log=x, xlog=TRUE, xaxp=c(1, 
2, 3));
 

Re: [R] Logarithmic axis

2007-11-20 Thread Julian Burgos
Hey John,

You can do simply

plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),log=x)

but if you want to fine tune where the tick marks are, you can do it by 
hand.

kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
reizstaerke - c(76, 92, 108, 124);
plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),axes=F)
box()
axis(1,at=log10(seq(75,125,by=5)),label=seq(75,125,by=5))
axis(2)

The obvious reason that you are getting a plot with a single 100 and 
nothing else is that the range of the values in the reizstaerke vector 
is away from 10 and from 1000.  If you really want to have the log scale 
in the way you described, you could do something like this:

plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),axes=F,xlim=log10(c(1,1000)))
box()
axis(1,at=log10(c(1,10,100,1000)),label=c(1,10,100,1000))
axis(2)

Julian


John Wiedenhoeft wrote:
 Hi there,
 
 I guess this must be a standard issue, but I'm starting to go crazy with it. 
 I 
 simply want a plot with the x axis being logarithmic, having labels 1, 10, 
 100..., and ten unlabelled ticks between each of them - just as they 
 introduce logarithmic axis at school. I've played around a bit with log=x, 
 xlog=T (where exactly is the difference here?), xaxp, and xaxt (unfortunately 
 xaxt=l isn't implemented). The best I get is a plot with an axis having a 
 single 100 and nothing else...
 
 here is what I've tried:
 
 pdf(file=kennlinien.pdf);
 par(log=x, xlog=TRUE);
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 #plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, kennlinie2)), 
 xlim=c(0, max(reizstaerke)), log=x, xlog=TRUE, xaxp=c(1, 2, 1), type=b);
 #plot(reizstaerke, kennlinie1, type=b, log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 plot(reizstaerke, kennlinie1, type=b,usr=c(min(reizstaerke), 
 max(reizstaerke), min(kennlinie1, kennlinie2), max(kennlinie1, kennlinie2)), 
 log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 #points(reizstaerke, kennlinie2, xlog=TRUE, xaxp=c(1, 3, 3), type=b);
 dev.off();
 
 Certainly I've missed something, but I can't figure it out.
 
 Any help appreciated,
 Cheers, 
 John
 
 
 
 platform   i486-pc-linux-gnu
 arch   i486
 os linux-gnu
 system i486, linux-gnu
 status
 major  2
 minor  4.1
 year   2006
 month  12
 day18
 svn rev40228
 language   R
 version.string R version 2.4.1 (2006-12-18)
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Logarithmic axis

2007-11-20 Thread Julian Burgos
Like always, there is much to be learned from the R-help list!  Another 
message had a much simpler approach.

plot(xy.coords(reizstaerke, kennlinie1, log=x), log=x)

Julian


Julian Burgos wrote:
 Hey John,
 
 You can do simply
 
 plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),log=x)
 
 but if you want to fine tune where the tick marks are, you can do it by 
 hand.
 
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),axes=F)
 box()
 axis(1,at=log10(seq(75,125,by=5)),label=seq(75,125,by=5))
 axis(2)
 
 The obvious reason that you are getting a plot with a single 100 and 
 nothing else is that the range of the values in the reizstaerke vector 
 is away from 10 and from 1000.  If you really want to have the log scale 
 in the way you described, you could do something like this:
 
 plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),axes=F,xlim=log10(c(1,1000)))
 box()
 axis(1,at=log10(c(1,10,100,1000)),label=c(1,10,100,1000))
 axis(2)
 
 Julian
 
 
 John Wiedenhoeft wrote:
 Hi there,

 I guess this must be a standard issue, but I'm starting to go crazy 
 with it. I simply want a plot with the x axis being logarithmic, 
 having labels 1, 10, 100..., and ten unlabelled ticks between each of 
 them - just as they introduce logarithmic axis at school. I've played 
 around a bit with log=x, xlog=T (where exactly is the difference 
 here?), xaxp, and xaxt (unfortunately xaxt=l isn't implemented). The 
 best I get is a plot with an axis having a single 100 and nothing else...

 here is what I've tried:

 pdf(file=kennlinien.pdf);
 par(log=x, xlog=TRUE);
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 #plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, kennlinie2)), 
 xlim=c(0, max(reizstaerke)), log=x, xlog=TRUE, xaxp=c(1, 2, 1), 
 type=b);
 #plot(reizstaerke, kennlinie1, type=b, log=x, xlog=TRUE, xaxp=c(1, 
 2, 3));
 plot(reizstaerke, kennlinie1, type=b,usr=c(min(reizstaerke), 
 max(reizstaerke), min(kennlinie1, kennlinie2), max(kennlinie1, 
 kennlinie2)), log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 #points(reizstaerke, kennlinie2, xlog=TRUE, xaxp=c(1, 3, 3), type=b);
 dev.off();

 Certainly I've missed something, but I can't figure it out.

 Any help appreciated,
 Cheers, John



 platform   i486-pc-linux-gnu
 arch   i486
 os linux-gnu
 system i486, linux-gnu
 status
 major  2
 minor  4.1
 year   2006
 month  12
 day18
 svn rev40228
 language   R
 version.string R version 2.4.1 (2006-12-18)

 __
 R-help@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.
 


__
R-help@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.