[R] Logarithmic axis
Julian Burgos
jmburgos at u.washington.edu
Wed Nov 21 01:46:50 CET 2007
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
> day 18
> svn rev 40228
> language R
> version.string R version 2.4.1 (2006-12-18)
>
> ______________________________________________
> 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