rnorouzian
rnorouzian

Reputation: 7517

Y axis not showing values correctly R plot

I'm wondering what is the fix for my Y axis in my plot below? Y axis is supposed to be comprised of of SEVEN values (.1, 1, 10, 100, 1000, 10000, 1000000)? But they don't show correctly on the plot?

Here is my R code?

plot(1, 1, type = "n", xlim = c(0,1.5), ylim = c(.1, 100000), ann=F,bty="n",yaxt="n")

axis(side=2, at = 10^(-1:5),label=c(format(10^(-1:5),scientific=F) ))

Upvotes: 0

Views: 2791

Answers (3)

gsun
gsun

Reputation: 427

I actually saw you left comment on your last question, so I also added a comment there. It's problem with the scale. 0.1, 1 and 10 are all clustered together, because there's only space to show first label. This code will give me more labels, but the ideal way is to do it in log scale:

axis(side=2, at = 10^(-1:5),label=c(format(10^(-1:5),scientific=FALSE)),las=1)

Upvotes: 2

IRTFM
IRTFM

Reputation: 263499

The axis function tries very hard not to have overlapping labels and the rule of no-overlap includes a margin of whitespace, so you can start to see a difference in number of labels that will fit as you reduce the cex.axis:

axis(side=2, cex.axis=0.7, at = 10^(-1:5),label=c(format(10^(-1:5),scientific=F) ))
axis(side=2, cex.axis=0.6, at = 10^(-1:5),label=c(format(10^(-1:5),scientific=F) ))

Upvotes: 1

Dave2e
Dave2e

Reputation: 24149

You need to specify the y axis as a logarithmic scale with the log="y" parameter:

plot(1, 1, type = "n", xlim = c(0,1.5), ylim = c(.1, 100000), ann=F, bty="n", log="y", yaxt="n")
axis(side=2, at = 10^(-1:5),label=c(format(10^(-1:5),scientific=F) ) )

Upvotes: 1

Related Questions