Displaying minor logarithmic ticks in x-axis in R

Viewed 15928

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 able to change the major ticks format from 1, 2, 3 and so on to 10^0, 10^1, 10^2, 10^3 using the solution given to me in my previous question. I used the following code for the major ticks :

major.ticks <- axTicks(1)
labels <- sapply(major.ticks,function(i)
            as.expression(bquote(10^ .(i)))
          )
axis(1,at=major.ticks,labels=labels)

Can this be edited to just mark the minor ticks without labeling them?

8 Answers

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: enter image description here

The x axis labels in the first plot on this page is in error. The minor ticks are not properly distributed.

Related