代码
a <- 10^-7
f <- function(x) 1+a*cos(x)
plot(f, 0, 2*pi)
产生
但较小的a
值(例如10^-8
)会产生以下结果:
如何在后一种情况下使y轴显示第一个图中的小数位? (我不使用ggplot2。)
答案 0 :(得分:1)
我找到了你需要为你的情节添加更多小数的答案
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)
答案 1 :(得分:1)