簡體   English   中英

圖外的圖例位置

[英]Legend position outside graph

我嘗試將圖例放在圖表之外。 如您所見,這僅成功了一半。

我必須在哪里更改號碼?

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)

您沒有提供可復制的示例。 因此,很難說出問題的所在和位置。 什么是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")

Imgur

那是你要的嗎?

編輯或者如果您想在旁邊添加圖例,請執行以下操作:

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

謝謝您的回答! 對於那個很抱歉! 您的示例看起來與我想要的相似!

顏色是:colfunc <-colorRampPalette(c(“ darkblue”,“ lightblue”))colfunc(12)

2007年:12條輪廓線(穿過積聚葉的交叉輪廓)樣本:

dput(head(Profile07_6))結構(list(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.23,415.03,414.85),X9 = c(401.35,401.23,401.11,400.94,400.78,400.7),X8 = c(380.04,379.85,379.64,379.38,379.15,378.96),X7 = c( 358.95,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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM