我正在嘗試從格子包中製作一個水平圖(也顯示輪廓線)。我有幾個問題(如下所述)。R levelplot colorkey標籤和顏色範圍
邁德特: https://www.dropbox.com/s/ht55g0qlkiou2x2/growth.matrix.stackoverflow.xlsx
require(lattice)
require(latticeExtra)
require(xlsx)
#matrix to be plotted
growth.matrix<-as.matrix(read.xlsx("C:/Users/eckmannm/Dropbox/growth.matrix.stackoverflow.xlsx",sheetName="p4.pct",colIndex=2:8,startRow=3,endRow=15,header=FALSE))
#column values
TempRange<-as.numeric(c(0, 2, 4, 6, 8, 10, 12))
#row values
MeanTemp<-as.numeric(c(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18))
#x and y axis labels
x.range<-as.numeric(c(6, 8, 10, 12, 14, 16, 18))
#color ramp
col.l <- colorRampPalette(c('red', 'orange', 'yellow', 'green', 'cyan', 'blue'))
colorplot<-
levelplot(
growth.matrix,
row.values=(MeanTemp),
column.values=(TempRange),
col.regions=col.l,
at=seq(from=0,to=1.01,length=100),
lattice.options=list(key=list(cex=4)),
panel = panel.2dsmoother,
scales=list((x=list(labels=MeanTemp)), y=list(labels=TempRange)),
colorkey=list(at=as.numeric(factor(c(seq(from=0, to=1, by=.20)))),
labels=as.character(c("0", "20%", "40%", "60%", "80%", "100%")),
col=(col.l)))
contourplot<-
contourplot(
growth.matrix,
row.values=MeanTemp,
column.values=TempRange,
at=seq(from=0, to=1.01, by=.2),
panel=panel.2dsmoother,
label.style=("flat"),
lwd=2,
labels=(list(cex=1.5,labels=(c("0", "20%", "40%", "60%", "80%", "100%")))))
(final.plot= (colorplot + contourplot))
>> dput(head(growth.matrix))
structure(c(0.117236699239957, NA, 0.416693811074919, NA, 0.776134455117953,
NA, NA, 0.263952225841477, NA, 0.582491856677524, NA, 0.855917480998914,
NA, NA, 0.423344191096634, NA, 0.6792888165038, NA, NA, NA, NA,
0.5164223669924, NA, 0.698561346362649, NA, NA, NA, NA, 0.534989142236699,
NA, NA, NA, NA, NA, NA, 0.507193268186754, NA, NA, NA, NA, NA,
NA), .Dim = 6:7, .Dimnames = list(NULL, c("X2", "X3", "X4", "X5",
"X6", "X7", "X8")))
1)I真的希望在着色區域的邊緣(軸標籤和圖形)之間,除去垂直白邊。
2)我想圖例有離散標籤,具有不同斷點比色
3)由於某種原因,輪廓線標籤繪製斷圖形的???
任何幫助將不勝感激!提前致謝。
我不斷收到您的代碼錯誤....你可以發佈一個可重複的例子嗎? –
@IShouldBuyABoat:代碼工作正常,但你需要加載一些包,我更新了代碼 – nico