2012-08-12 141 views
2

我試圖在我的地塊右側安裝第二個ylab,但我無法獲得所需的額外空間。如果這是不可能的,繪製圖中的比例值可能是一個解決方案。 我的代碼(模擬數據,但在右邊距的問題是存在的):在R中獲得地塊利潤率

dev.new(width= 16, height= 7) 
par(cex= 0.9) 
plot(1:100, type="n", xlab = "", ylab = "", axes = F, las = 2, cex = 0.7) 
axis(4, at = c (0, 30, 60, 90, 120, 150, 180), labels = c("0", "30", "60", "90", "120", "150", "180"), las = 0, cex.axis = .8,col.lab = "gray80", 
tck = 0.01) 
rect(153, -5.5, 169, 185, col = "gray80", border = NA) 
rect(246, -5.5, 272, 185, col = "gray80", border = NA) 
lines(1:200, col = "gray20") 
#text("Moon phase (º)", 330, 90, cex = .9) 
mtext(side = 4, text = "Moon phase (º)", line = 2, cex = .9) 
mtext(side = 1, text = "Dates", line = 4, cex = .9) 

par(new = T) 
plot(1:220, type = "n", lwd= 1.2, xlab= "", ylab= "Photoperiod (h)", axes = F, cex = .8, col.lab = "red") 
axis(side= 1, at = c (1, 20, 51, 82, 112, 143, 173, 204, 235, 264, 295, 324), labels = c ("12 Jun'07", "1 Jul'07", "1 Aug'07", "1 Sep'07", "1 Oct'07", "1 Nov'07", "1 Dec'07", "1 Jan'08", "1 Feb'08", "1 Mar'08", "1 Apr'08", "30 Apr'08"), las = 2, cex.axis = .75) 
axis (side = 2, at = c(12, 13, 14, 15, 16), labels = c("12", "13", "14", "15", "16"), cex.axis = .8, las = 2) 
box() 

感謝你的幫助,

桑蒂

+0

你可以添加你的劇情截圖? - 我測試了你的代碼,我在右邊的站點看到了第二個座標軸(不過左邊的站點被嚴重調整了......)。 – 2012-08-12 17:44:18

+0

我對這個問題有同樣的困難。缺少的是一個聲明,錯誤是「月相」在邊緣區域之外。明顯的問題是將y軸定位在左側。 – 2012-08-12 17:48:31

+0

謝謝大家。 Santi – 2012-08-12 19:46:42

回答

4

見參數三月的par。這將設置您的繪圖區域的邊距(底部,左側,頂部,右側;有關詳細信息,請參閱?par)。

dev.new(width= 16, height= 7) 
## set outer margins 
par(mar=c(5, 4, 4, 4), cex= 0.9) 
plot(1:100, type="n", xlab = "", ylab = "", axes = F, las = 2, cex = 0.7) 
axis(4, at = c (0, 30, 60, 90, 120, 150, 180), labels = c("0", "30", "60", "90", "120", "150", "180"), las = 0, cex.axis = .8,col.lab = "gray80", 
tck = 0.01) 
rect(153, -5.5, 169, 185, col = "gray80", border = NA) 
rect(246, -5.5, 272, 185, col = "gray80", border = NA) 
lines(1:200, col = "gray20") 
#text("Moon phase (º)", 330, 90, cex = .9) 
mtext(side = 4, text = "Moon phase (º)", line = 2, cex = .9) 
mtext(side = 1, text = "Dates", line = 4, cex = .9) 

par(new = T) 
plot(1:220, type = "n", lwd= 1.2, xlab= "", ylab= "Photoperiod (h)", axes = F, cex = .8, col.lab = "red") 
axis(side= 1, at = c (1, 20, 51, 82, 112, 143, 173, 204, 235, 264, 295, 324), labels = c ("12 Jun'07", "1 Jul'07", "1 Aug'07", "1 Sep'07", "1 Oct'07", "1 Nov'07", "1 Dec'07", "1 Jan'08", "1 Feb'08", "1 Mar'08", "1 Apr'08", "30 Apr'08"), las = 2, cex.axis = .75) 
axis (side = 2, at = c(12, 13, 14, 15, 16), labels = c("12", "13", "14", "15", "16"), cex.axis = .8, las = 2) 
box() 
+0

非常感謝,mar()解決了這個問題。我試圖把它放在dev.new()中,顯然沒有工作 – 2012-08-12 19:42:53

4

在上線#2你的代碼中使用:

par(cex= 0.9,mar=c(6,4,6,4)) 
+0

非常感謝。是的,par(mar())解決了這個問題 – 2012-08-12 19:45:41