2015-01-14 49 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