在R中获得地块利润率
问题描述:
我试图在我的地块右侧安装第二个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()
感谢你的帮助,
桑蒂
答
见参数三月的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
答
在上线#2你的代码中使用:
par(cex= 0.9,mar=c(6,4,6,4))
+0
非常感谢。是的,par(mar())解决了这个问题 – 2012-08-12 19:45:41
你可以添加你的剧情截图? - 我测试了你的代码,我在右边的站点看到了第二个坐标轴(不过左边的站点被严重调整了......)。 – 2012-08-12 17:44:18
我对这个问题有同样的困难。缺少的是一个声明,错误是“月相”在边缘区域之外。明显的问题是将y轴定位在左侧。 – 2012-08-12 17:48:31
谢谢大家。 Santi – 2012-08-12 19:46:42