Displaying minor logarithmic ticks in x-axis in R

前端 未结 8 464
一个人的身影
一个人的身影 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:18

    There is the minorAxis function in the StratigrapheR package, that can be used for any kind of minor ticks. It can be used with the seq_log function to make logarithmic ticks:

    library(StratigrapheR)
    
    x <- exp(rnorm(200, 5))
    hist(log10(x), 20, xaxt="n", xlim=c(0, 4), xlab = "x", main = "Logarithmic Histogram of x")
    
    ticks <- seq_log(10^0,10^4, divide = T)
    
    lab <- sapply(0:4, function(i) as.expression(bquote(10^ .(i))))
    
    minorAxis(1, at.maj = log10(ticks[[1]]), at.min = log10(ticks[[2]]), labels = lab)
    

    Gives:

提交回复
热议问题