[R] minor tick marks on boxplot log scale

David Stevens david.stevens at usu.edu
Thu May 8 01:35:36 CEST 2014


On closer inspection, change n=5 to n=10 in

major.ticks <- pretty(lims,n=5)

Then, I get 10^0, 10^1, etc. with all the minors. Is this what you want?

David

On 5/7/2014 10:32 AM, Shane Carey wrote:
> Hey,
>
> Im using the function below to create minor tick marks on log scale. It
> only plots every second marker, i.e. 10^0, 10^2 and so on. How do I get it
> to plot at every interval? Thanks
>
> minor.ticks.axis <- function(ax,n,t.ratio=0.5,mn,mx,...){
>
>    lims <- par("usr")
>    if(ax %in%c(1,3)) lims <- lims[1:2] else lims[3:4]
>
>    major.ticks <- pretty(lims,n=5)
>    if(missing(mn)) mn <- min(major.ticks)
>    if(missing(mx)) mx <- max(major.ticks)
>
>    major.ticks <- major.ticks[major.ticks >= mn & major.ticks <= mx]
>
>    labels <- sapply(major.ticks,function(i)
>              as.expression(bquote(10^ .(i)))
>            )
>    axis(ax,at=major.ticks,labels=labels,...)
>
>    n <- n+2
>    minors <- log10(pretty(10^major.ticks[1:2],n))-major.ticks[1]
>    minors <- minors[-c(1,n)]
>
>    minor.ticks = c(outer(minors,major.ticks,`+`))
>    minor.ticks <- minor.ticks[minor.ticks > mn & minor.ticks < mx]
>
>
>    axis(ax,at=minor.ticks,tcl=par("tcl")*t.ratio,labels=FALSE)}
>
> x <- 10^(0:8)
> y <- 1:9
> plot(log10(x),y,xaxt="n",xlab="x",xlim=c(0,9))
> minor.ticks.axis(1,9,mn=0,mx=8)
>
>
> Thanks
>
>

-- 
David K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stevens at usu.edu



More information about the R-help mailing list