[英]R levelplot remove outer border (adjust plot border)
我正在使用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)
這就是它的樣子。我不喜歡邊緣上的雙線。
編輯:這是一個可重現的示例:
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="")
對於可能有用的未來參考,我通過快速查看prepanel.default.levelplot()
使用的代碼來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) {
一點點的挖掘表明,許多par命令可能無法使其適應Lattice封裝圖形 。 例如,par(bty ='n') 在此levelplot示例中不起作用 。
與基礎R圖不同,晶格圖不受par()函數中設置的許多選項的影響。 要查看可以更改的選項,請查看help(xyplot)。 在高級繪圖功能中設置這些選項通常是最容易的。您可以編寫修改面板渲染的功能。
嘗試將軸的顏色直接傳遞到圖形ala中,方法是Yangchen Lin建議的方法: R格子3d圖:更改面板邊框厚度時刻度消失
axis.line = list(col='transparent')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.