2017-05-04 96 views
0

我想繪製一個x和y刻度的水平圖作爲log10刻度。R:如何繪製日誌刻度尺的水平圖

例如,我有一個這樣的正常水平的情節。

x <- 10*1:nrow(volcano) 
y <- 10*1:ncol(volcano) 
filled.contour(x, y, volcano, color = terrain.colors, plot.title = title(main = "Volcano topolgy", xlab = "Meters North", ylab = "Meters West"), plot.axes = { axis(1, seq(100, 800, by = 100)); axis(2, seq(100, 600, by = 100)) }, key.title = title(main = "Height\n(meters)"), key.axes = axis(4, seq(90, 190, by = 10))) 

enter image description here

但是,x和y尺度無法登錄蜱尺度。我發現其他庫「latticeExtra」具有日誌刻度尺功能。例如,從上面使用相同的x和y我可以繪製日誌記號,但不能填充輪廓數據。

library(lattice) 
library(latticeExtra) 
xyplot(y ~ x, scales = list(x = list(log = 10), y = list(log = 10)), xscale.components = xscale.components.log10ticks, yscale.components = yscale.components.log10ticks) 

enter image description here

怎樣繪製與日誌勾秤的水平情節?我想在稍後的日誌位置繪製分佈圖。

在此先感謝。如果你想使用filled.contour可以直接logtransform的xy數據和自定義axis聲明中調整相應的軸保持,但它不是很優雅

回答

1

下面是使用latticelatticeExtra

library(lattice) 
library(latticeExtra) 

xx <- 1:nrow(volcano) 
yy <- 1:ncol(volcano) 

levelplot(
    x = volcano, 
    xlim = range(xx), 
    ylim = range(yy), 
    scales = list(x = list(log = 10), y = list(log = 10)), 
    xscale.components = xscale.components.log10ticks, 
    yscale.components = yscale.components.log10ticks 
) 

enter image description here

替代
1

(在base::plotlog = "xy"參數可悲的是沒有做filled.contour任何東西) :

x <- log(10*1:nrow(volcano)) 
y <- log(10*1:ncol(volcano)) 
filled.contour(x, y, volcano, color = terrain.colors, 
       plot.title = title(main = "Volcano topolgy", 
            xlab = "Meters North", 
            ylab = "Meters West"), 
       plot.axes = { axis(1, at = log(seq(100, 800, by = 100)), labels = seq(100, 800, by = 100)); 
               axis(2, at = log(seq(100, 600, by = 100)), labels = seq(100, 600, by = 100)) }, 
       key.title = title(main = "Height\n(meters)"), 
       key.axes = axis(4, seq(90, 190, by = 10))) 

enter image description here 你也可以嘗試,如果ggplot2scale_y_log10()scale_x_log10()會爲你工作,看this question and answer