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

标签 r correlation lattice levelplot

我正在 R 中使用 levelplot (lattice) 创建相关热图。
我想要盒子之间的边界,但不要沿着外面,因为它会干扰情节边界。
如何从框中删除外边框?

这是我的代码:

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)

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

enter image description here

编辑:这是一个可重现的示例:
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="")

最佳答案

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

只需使用 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="")

enter image description here

对于可能对 future 有用的引用,我通过快速查看 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) {  

关于R levelplot 删除外边框(调整绘图边框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19731800/

相关文章:

python - 在 2 个数组之间移动均方误差 'valid' ,它们完全重叠

r - cor(mydata) 中的错误 : 'x' must be numeric

r - 通过单击识别现有 splom 中的子面板

python - 使用 rpy2 设置点阵图选项时出现问题

r - 如何为在格子中使用 splom 绘制的相关系数添加 p 值?

r - 根据命名向量改变列,如查找表

R:ggplot2,我可以让 facet/strip 文本环绕吗?

Python-根据相关矩阵生成数字

R 数据框上的 Shiny 过滤器

r - 将顶点大小与 igraph 中的标签大小匹配