我正在 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)
这是它的样子..我不喜欢边缘的双线..
编辑:这是一个可重现的示例:
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="")
对于可能对 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/