Search code examples
rhistogramlogarithm

Make y-axis logarithmic in histogram using R


Hi I'm making histogram using R, but the number of Y axis is so large that I need to turn it into logarithmic.See below my script:

hplot<-read.table("libl")
hplot
pdf("first_end")
hist(hplot$V1, breaks=24, xlim=c(0,250000000), ylim=c(0,2000000),main="first end mapping", xlab="Coordinates")
dev.off()

So how should I change my script? thx


Solution

  • You can save the histogram data to tweak it before plotting:

    set.seed(12345)
    x = rnorm(1000)
    
    hist.data = hist(x, plot=F)
    hist.data$counts = log10(hist.data$counts)
    
    dev.new(width=4, height=4)
    hist(x)
    
    dev.new(width=4, height=4)
    plot(hist.data, ylab='log10(Frequency)')
    

    enter image description here

    enter image description here