R matplot添加第二个X轴

时间:2015-09-19 09:32:01

标签: r graph axis-labels

我是一个比R更新的python用户。我有以下代码来绘制这个图:

meangf <- c(-0.4183021,-0.4160919, -0.4140347, -0.4121201, -0.4103434, -0.4087048, -0.4058971, -0.4047143, -0.4036499, -0.4026888, -0.4018101, -0.4009911)
meanef <- c(-0.4368967, -0.4361810, -0.4354082, -0.4345807, -0.4337014, -0.4327733, -0.4308227, -0.4298084, -0.4287604, -0.4276822, -0.4265775, -0.4254498)
meanbf <- c(-0.3754438, -0.3808981, -0.3762082, -0.3688898, -0.3645197, -0.3613621, -0.3585380, -0.3562512, -0.3553108, -0.3545954, -0.3540907, -0.3536820)

x <- c(2685, 2754, 2825, 2898, 2973, 3050, 3207, 3287, 3369, 3453, 3539, 3627)

matplot(x, cbind(meangf, meanef, meanbf), col=c(4,2,3), type="l",lty=c(1,1,1) ,xlab="Bandwidth", ylab="Mean", main="Age25_44 Estimate Parameter")
legend("topright",legend=c("Gaussian Fixed", "Expnential Fixed", "Boxcar Fixed"), lty=c(1,1,1),lwd=2
,col=c(4,2,3),
ncol=3,bty="n",cex=0.8,
text.col=c(4,2,3),inset=0.01)

enter image description here

我想在图表顶部添加第二个x轴,例如

 x2 <- c(20000, 22000, 24000, 26000, 28000, 30000, 32000, 34000, 36000, 38000, 40000, 42000)

我该怎么做?

编辑:

我喜欢的解决方案类似于这个问题How to add a second x-axis in matplotlib

1 个答案:

答案 0 :(得分:1)

您可以使用axis()

where = seq(from=min(x), to=max(x), length.out=length(x2))
axis(1, where, labels=x2, padj=2)

padj可让您进一步放下轴