Displaying minor logarithmic ticks in x-axis in R

前端 未结 8 485
一个人的身影
一个人的身影 2021-02-02 15:31

I have a normal distribution plot and a histogram plot with x axis in log scale displaying 0, 10^0, 10^1 ... I want to include minor ticks between the major ones. Actually I was

8条回答
  •  花落未央
    2021-02-02 16:09

    Here is a simple function to to this:

    log10.axis <- function(side, at, ...) {
        at.minor <- log10(outer(1:9, 10^(min(at):max(at))))
        lab <- sapply(at, function(i) as.expression(bquote(10^ .(i))))
        axis(side=side, at=at.minor, labels=NA, tcl=par("tcl")*0.5, ...)
        axis(side=side, at=at, labels=lab, ...)
    }
    

    Here is an example:

    x <- exp(rnorm(200, 5))
    hist(log(x), 20, xaxt="n", xlim=c(0, 8))
    log10.axis(1, at=seq(0, 8, 2))
    

    Gives:

提交回复
热议问题