2017-05-04 95 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