R levelplot删除外边框(调整图边框)

Pau*_*aul 5 r lattice correlation levelplot

我正在使用levelplot(晶格)在R中创建相关热图.我喜欢盒子之间的边界,但不喜欢外面,因为它会干扰情节边界.如何从框中删除外边框?

这是我的代码:

levelplot(matrix, border="black", 
          colorkey=list(height=.25, space="right", at=seq(-1, 1, .25), cuts=7), 
          scales=list(y=(list(cex=1)), tck = c(1,0), x=list(cex=1, rot=90)),
          main="Leaf Correlations", xlab="", ylab="", 
          col.regions=scalebluered)
Run Code Online (Sandbox Code Playgroud)

这就是它的样子..我不喜欢边缘上的双线..

在此输入图像描述

编辑:这是一个可重复的例子:

data(mtcars)
cars.matrix <- as.matrix(mtcars[c(2:8)])
cars.corr <- cor(cars.matrix)
levelplot(cars.corr, border="black", colorkey=list(height=.25, space="right", 
          at=seq(-1, 1, .25), cuts=7), 
          scales=list(y=(list(cex=1)), tck = c(1,0), x=list(cex=1, rot=90)), 
          xlab="", ylab="")
Run Code Online (Sandbox Code Playgroud)

Jos*_*ien 5

好的,如果有点晦涩,解决这个问题很简单。

只需用于lattice.options()重置axis.padding用于因子的值,将其从默认值 0.6(一点填充)更改为 0.5(无填充),您应该没问题:

lattice.options(axis.padding=list(factor=0.5))

## An example to show that this works
data(mtcars)
cars.matrix <- as.matrix(mtcars[c(2:8)])
cars.corr <- cor(cars.matrix)
levelplot(cars.corr, border="black", colorkey=list(height=.25, space="right", 
          at=seq(-1, 1, .25), cuts=7), 
          scales=list(y=(list(cex=1)), tck = c(1,0), x=list(cex=1, rot=90)), 
          xlab="", ylab="")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

对于可能有用的未来参考,我通过快速查看prepanel.default.levelplot(). (prepanel.***除其他外,各种功能负责确定应分配给每个面板的坐标和最小区域,以便要绘制到其中的对象都能很好地适合。)

head(prepanel.default.levelplot, 4)

1 function (x, y, subscripts, ...)                    
2 {                                                   
3     pad <- lattice.getOption("axis.padding")$numeric
4     if (length(subscripts) > 0) {  
Run Code Online (Sandbox Code Playgroud)