控制fill.contour图上的x轴时间戳 - R.

时间:2016-12-16 14:53:14

标签: r plot timestamp contour

我一直在查看文档,但我无法弄清楚如何控制R中filled.contour()图的x轴上的时间戳。我尝试过axis.POSIXct()和{{1} }。但这对我都不起作用。

这是我的简化示例:

plot.axes = {}

哪些输出:enter image description here

X轴标签采用年份格式。我希望每个月的格式为x1 <- seq(as.Date("2016-01-01"),as.Date("2018-07-01"),by="month") z1 <- c(0.45062130 ,0.51136174 ,0.6 ,0.8 ,0.29481738 ,0.6 ,0.27713756 ,0.62638512 ,0.23547530,0.29253901 ,0.75899501 ,0.67779756 ,0.51831742 ,0.08050147 ,0.71183739 ,0.13154414 ,0.79406706 ,0.13154414,0.03434758 ,0.59573892 ,0.22102821 ,0.13154414 ,0.13154414 ,0.13154414 ,0.13154414 ,0.13154414 ,0.23692593,0.95215104 ,0.38810846 ,0.17970580 ,0.05176054) z2 <- z1^2 z3 <- z2^2 df <- data.frame(x1,z1,z2,z3) time <- c(x1) depths <- c(1,2,3) temp2 <- as.matrix(data.frame(df$z1,df$z2,df$z3)) temp2<- matrix(temp2,ncol=ncol(temp2), dimnames = NULL) filled.contour(time,depths,temp2, col=(matlab.like2(28)), ylab="Depth", xlab="Time", key.title=title(expression(' Temp ('*degree*'C)')),xaxs="i") (例如5月16日,6月16日等)。我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

以下是使用plot.axes选项与axis.Date进行操作的方式。

filled.contour(time,depths,temp2, #col=(matlab.like2(28)),
       ylab="Depth", xlab="Time",
       plot.axes = { axis.Date(side=1,x=time,at=time,format="%b-%y"); axis(2) },
       key.title=title(expression('  Temp ('*degree*'C)')),xaxs="i")

enter image description here