2013-11-01 216 views
5

我用水平圖(格子)在R中創建一個關聯熱圖。 我想要框之間的邊界,但不是沿着外部,因爲它干擾了情節邊界。 如何從盒子中取出外框?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) 

,這裏是什麼樣子。我不喜歡邊緣上的雙回線..

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="") 
+0

也許去除外邊框代替?我的格是有點生疏,但也許像'par.settings =名單(axis.line =名單(LWD = 0)'或'也許山坳=「白色」'也許吧。 – joran

+0

嗯...這似乎刪除所有線路,包括蜱... – joran

+0

任何機會,你可以做一個最小的可重複的例子 –

回答

4

行,這樣做的解決方法是簡單,如果一個位晦澀。

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

對於可能有用的將來參考,我通過快速瀏覽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) { 
+0

謝謝!不知道我會想出來的! 在此期間,我發現了corrplot庫有一些不錯的選擇,並可能是一個更好的路線,我去不是試圖定製levelplot我的需要。 使用我上面的例子,這也得到了我想要的: '庫(corplot) corrplot(cars.corr,method =「shade」,shade.col = NA,tl.col =「black」,tl.srt = 45,addgrid.col =「black」)' – Paul

+1

@Paul - 可以理解的,儘管我剛剛添加了一些註釋,希望能夠讓我的思維過程更容易被您和其他人重現。 –

1

有點挖掘顯示that a lot of the par commands may not make it to Lattice package graphics。例如,par(bty ='n')won't work in this levelplot example

與基R圖不同,格圖不受par()函數中設置的許多選項的影響。要查看可以更改的選項,請查看幫助(xyplot)。在高級繪圖函數中設置這些選項通常是最容易的...您可以編寫修改面板渲染的函數。

嘗試直接傳遞軸顏色到圖形ALA該方法通過Yangchen Lin這裏建議:R lattice 3d plot: ticks disappear when changing panel border thickness

axis.line = list(col='transparent') 
+0

試過,它似乎並沒有做任何事情。 .. – Paul

+0

不知道它是否能在這種特定的實例,但完整的選項擺脫軸線將是'par.settings =名單(axis.line =名單(COL =「透明」))'。 – user1521655