正如krlmlr所示,最簡單的解決方案是稍微修改plotrix::draw.circle()
。對數 - 對數座標系扭曲以線性標度給出的圓的座標;以抵消這一點,你只需要exponentiate計算的座標,我在下面的代碼打上## <-
行所做的:
library("plotrix")
draw.circle.loglog <-
function (x, y, radius, nv = 100, border = NULL, col = NA, lty = 1,
lwd = 1)
{
xylim <- par("usr")
plotdim <- par("pin")
ymult <- (xylim[4] - xylim[3])/(xylim[2] - xylim[1]) * plotdim[1]/plotdim[2]
angle.inc <- 2 * pi/nv
angles <- seq(0, 2 * pi - angle.inc, by = angle.inc)
if (length(col) < length(radius))
col <- rep(col, length.out = length(radius))
for (circle in 1:length(radius)) {
xv <- exp(cos(angles) * log(radius[circle])) * x[circle] ## <-
yv <- exp(sin(angles) * ymult * log(radius[circle])) * y[circle] ## <-
polygon(xv, yv, border = border, col = col[circle], lty = lty,
lwd = lwd)
}
invisible(list(x = xv, y = yv))
}
# Try it out
x = 10^(-1 * c(5:0))
y = x ^-1.5
plot (x, y, log="xy", type="o")
draw.circle.loglog(x = c(1e-2, 1e-3, 1e-4), y = c(1e2, 1e6, 1e2),
radius = c(2,4,8), col = 1:3)
[看到這裏](http://stackoverflow.com/questions/9265588/r-plotting-a-point-on-the-y-axis-when-the-x-axis-is-using-a-log-比例/ 9265840#9265840)進行相關討論。根據你想要的半徑單位的含義,你可能想在兩個座標指數行中用'10 ^(...)'代替'exp(...)'。 – 2013-04-13 07:57:05
好的,我已經修復了處理radius參數的方式。現在,半徑爲10意味着在x軸上以1爲中心的圓將其左邊緣設爲0.1,其右邊緣設爲10.(注意,一個半徑爲1的圓將被繪製爲一個點(即,右邊和左邊的x座標)。) – 2013-04-14 14:40:55
不錯,...你的draw.circle.loglog()應該definitley被添加到plotrix庫中。 – 2013-04-15 06:47:38