2015-01-14 54 views
0

我嘗試將圖例置於圖表之外。 這只是你看到的一半成功。圖例外的圖例位置

我必須在哪裏更改數字?

par(oma = c(0.1,1,0.1,1.5)) 
matplot(Profile2007, type = "l", lty = 1, col = colfunc(12), 
    ylab = "m asl", xlab="Distance along crossprofile [m]") 
legend("topright", inset=c(-0.33,-0.0012), legend=1:12, xpd=T, 
    horiz=F, col=colfunc(12), lty =1) 

回答

0

您沒有提供可重複的示例。所以很難說出你的問題在哪裏以及在哪裏。什麼是Profile2007?什麼是colfunc?所以,我們看不到你是「半成功」的。

不管怎樣,對我下面的作品,我模擬了一些數據:

Profile2007 <- matrix(rnorm(100*12), 100, 12) 

par(oma = c(0.1,1,0.1,1.5)) 
matplot(Profile2007, type = "l", lty = 1, col = rainbow(12), 
     ylab = "m asl", xlab = "Distance along crossprofile [m]") 
legend("topright", inset = c(-0.05,-0.1), legend = 1:12, xpd = TRUE, 
     horiz = TRUE, col = rainbow(12), lty = 1, bty = "n") 

​​

這是你想要的嗎?

編輯或者這樣,如果你想在旁邊的傳說:

Profile2007 <- matrix(rnorm(100*12), 100, 12) 

par(mar = c(5, 4, 4, 6) + 0.1) 
matplot(Profile2007, type = "l", lty = 1, col = rainbow(12), 
     ylab = "m asl", xlab = "Distance along crossprofile [m]") 
legend("right", inset = c(-0.17,0), legend = 1:12, xpd = TRUE, 
     horiz = FALSE, col = rainbow(12), lty = 1, bty = "n") 

Imgur

+0

對不起,'Comment'我回答... – user3216322

+0

@ user3216322對不起,但那個「答案」沒有提供很多信息。我無法運行你的代碼,因爲我沒有'Profile07_6'。請確保您的代碼可以在* new * R會話中無誤地運行。據我所知,你也可以用'grid()'來代替所有'abline'。 –

+0

@ user3216322我編輯了我的帖子。那是你要的嗎? –

0

謝謝你的回答! 對不起! 你的例子看起來類似於我想要的!

的顏色是: colfunc < - colorRampPalette(C( 「darkblue」, 「lightblue」)) colfunc(12)

2007:12條輪廓線(運行通過累積葉橫型材) 甲樣品:

dput(頭(Profile07_6)) 結構(列表(X12 = C(427.89,427.89,427.93,427.96,427.98, 428),X11 = C(421.36,421.34,421.32,421.28, 421.22,421.18), X10 = c(415.81,415.6,415.44,415 ,X8 = c(380.04,379.85, 379.64,379.38,379.15,378.96),X7 = c(358.95,p = 0.0001),X9 = c(401.35, 401.23,401.11,400.94,400.78,400.7) 359.13,359.34, 359.56,359.78,359.99),X6 = c(348.31,348.52,348.68,348.83, 348.96,349.11)),.names = c(「X12」,「X11」,「X10」,「X9 」, 「X8」, 「X7」, 「X6」),row.names = C(NA,6L)中,class = 「data.frame」)

的時候,圖形看起來像這樣

par(tcl=0.5) 
matplot(Profile07_6, type = "l", lty = 1, col = colfunc(7), ylim=c(290,440), 
     ylab = "m asl", xlab="Distance along crossprofile [m]", main ="2007") 
par(tcl=0.5) 
minor.tick(ny=5, nx=2, tick.ratio=0.5) 
abline(h=350, lty=3, col="grey33") 
abline(h=400, lty=3, col="grey33") 
abline(h=300, lty=3, col="grey33") 
abline(h=290, lty=3, col="grey") 
abline(h=310, lty=3, col="grey") 
abline(h=320, lty=3, col="grey") 
abline(h=330, lty=3, col="grey") 
abline(h=340, lty=3, col="grey") 
abline(h=360, lty=3, col="grey") 
abline(h=370, lty=3, col="grey") 
abline(h=380, lty=3, col="grey") 
abline(h=390, lty=3, col="grey") 
abline(h=410, lty=3, col="grey") 
abline(h=420, lty=3, col="grey") 
abline(h=430, lty=3, col="grey") 
abline(h=440, lty=3, col="grey") 
axis(4, at=c(290, 310, 320, 330, 340, 360, 370, 380, 390, 410, 420, 430, 440), 
    labels=c(290, 310, 320, 330, 340, 360, 370, 380, 390, 410, 420, 430, 440), 
    col.axis="grey33", las=0, cex.axis=0.7, tck=0.01, col = "grey33", padj = -2.1) 
+0

這是幫助的樣本嗎? – user3216322

+0

圖例應位於圖的右側,以便更容易地遵循顏色... – user3216322