Reputation: 250
The code
a <- 10^-7
f <- function(x) 1+a*cos(x)
plot(f, 0, 2*pi)
produces
but smaller values of a
(e.g. 10^-8
) produce the following:
How can I make the y-axis in the latter case show the decimal places as in the first plot? (I do not use ggplot2.)
Upvotes: 3
Views: 4742
Reputation: 1956
You can use formatC
and pretty
:
a <- 1e-10
plot(f, 0, 2*pi, yaxt="n") # no default y axis
p <- pretty(par("usr")[3:4]) # find nice breaks at actual y range
l <- formatC(p, format="f", digits=12) # format w/12 digits
axis(2, at=p, labels=l)
Upvotes: 1
Reputation: 2289
I found the answer you are needing to add more decimals to your plot
value = function(p){c(min(p$y),
mean(c(median(p$y),min(p$y))),
median(p$y),
mean(c(median(p$y),max(p$y))),
max(p$y))}
par(mar = c(5,5,4,2), mfrow = c(1,2))
options(digits=15, scipen = 999)
a <- 10^-7
f <- function(x) as.double(1+a*cos(x))
p1 = plot(f, 0, 2*pi, cex.axis = 0.7, las = 1, ylab = "", yaxt = "n", main = "a=10^-7")
axis(2, at = value(p1),labels = sprintf("%.8f", value(p1)), cex.axis = .7, las = 1)
a <- 10^-8
p2=plot(f, 0, 2*pi, cex.axis = 0.7, las = 1, ylab = "", yaxt = "n", main = "a=10^-8")
axis(2, at = value(p2),labels = sprintf("%.8f", value(p2)), cex.axis = .7, las = 1)
Upvotes: 1