Make y-axis logarithmic in histogram using R

LookIntoEast picture LookIntoEast · Oct 19, 2011 · Viewed 20k times · Source

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

Answer

John Colby picture John Colby · Oct 20, 2011

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