```
par(mar = c(5, 4, 4, 4) + 0.1,
cex.lab = 1.2,
cex.axis = 1.1,
mgp = c(2.5, 0.8, 0),
family = "serif")
# 主绘图区设置
plot(years, std_chrono, type = "l", lwd = 2, col = "#1f77b4",
xlab = "Year", ylab = "Ring Width Index (RWI)",
main = "Standard Chronology of Birch (1971-2020)",
xlim = c(1971, 2020), ylim = c(0, 2), # 固定y轴范围
axes = FALSE) # 关闭自动坐标轴
# 添加定制坐标轴
axis(1, pos = 0) # 下轴从y=0开始
axis(2, at = c(0, 1, 2), pos = 1971) # 左轴从x=1971开始
# 样本深度叠加
par(new = TRUE)
plot(years, samp_depth, type = "n",
axes = FALSE, xlab = "", ylab = "",
ylim = c(0, max(samp_depth)))
# 绘制图形元素
polygon(c(years, rev(years)),
c(rep(0, length(years)), rev(samp_depth)),
col = rgb(0.8, 0.8, 0.8, 0.3), border = NA)
lines(years, samp_depth, lty = 2, lwd = 1.5, col = "#ff7f0e")
# 添加右侧轴
axis(4, pos = 2020) # 右轴从x=2020开始
mtext("Sample Depth", side = 4, line = 2.5, cex = 1.2)
abline(v = 1991, col = "#2ca02c", lwd = 1.5, lty = 3)
# 图例
legend("topleft",
legend = c("RWI", "Sample Depth","EPS>0.85(Year1991)"),
col = c("#1f77b4", "#ff7f0e","#2ca02c"), lty = c(1,2,3),lwd = c(2, 1.5,1),
bty = "n", cex = 1.1)```这段代码生成的图不太好看,请将x轴限制在1971-2020之间,并且使得添加的绿色竖线链接1991这个点和右轴决定的曲线对应的点,并注意调整右轴范围为0-300,左轴范围0-1.5,图例位置不要和坐标轴交叉
最新发布