如何在对数刻度中使用 `polygon()`?
How to use `polygon()` in log scale?
我基本上想在图形后面遮蔽一个区域。
线性比例很容易做到。
x <- 1:20
y <- x^2
plot(x, y, type="l")
polygon(c(10,10,15,15),
c(-100,600,600,-100),
col=rgb(0,1,0,0.3),border=FALSE)
产生这个:
但是一旦你把 y 放在对数尺度上,
plot(x, y, type="l", log="y")
polygon(c(10,10,15,15),
c(-100,600,600,-100),
col=rgb(0,1,0,0.3),border=FALSE)
未显示任何内容。
玩 log = "y"
时要小心。如果您的 y
值为负,您将得到 NaN
。这正是这里发生的事情。尝试
plot(x, y, type="l", log="y")
polygon(c(10,10,15,15),
c(1e-7,600,600,1e-7), ## log(1e-7) is small enough
col=rgb(0,1,0,0.3),border=FALSE)
我基本上想在图形后面遮蔽一个区域。
线性比例很容易做到。
x <- 1:20
y <- x^2
plot(x, y, type="l")
polygon(c(10,10,15,15),
c(-100,600,600,-100),
col=rgb(0,1,0,0.3),border=FALSE)
产生这个:
但是一旦你把 y 放在对数尺度上,
plot(x, y, type="l", log="y")
polygon(c(10,10,15,15),
c(-100,600,600,-100),
col=rgb(0,1,0,0.3),border=FALSE)
未显示任何内容。
玩 log = "y"
时要小心。如果您的 y
值为负,您将得到 NaN
。这正是这里发生的事情。尝试
plot(x, y, type="l", log="y")
polygon(c(10,10,15,15),
c(1e-7,600,600,1e-7), ## log(1e-7) is small enough
col=rgb(0,1,0,0.3),border=FALSE)