r - 控制填充轮廓图上的 x 轴时间戳 - R

标签 r plot timestamp contour

我一直在查看文档,但我不知道如何控制filled.contour()的x轴上的时间戳R中的情节。我尝试过axis.POSIXct()plot.axes = {} 。但两者都不适合我。

这是我的简化示例:

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")

输出:enter image description here

X 轴标签采用年份格式。我希望格式为 %b-%y每个月(例如 5 月至 16 日、6 月至 16 日等)。我该怎么做呢?

最佳答案

以下是如何使用 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

关于r - 控制填充轮廓图上的 x 轴时间戳 - R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41186998/

相关文章:

r - 如何使用 dplyr::mutate_all 对选定列进行舍入

r - 在 par() 函数中设置轴的 lwd

r - 强制原点从 0 开始

r - ggplot_stat_密度2d 生态分布图

java - Ant:如何减去两个属性(包含时间戳)?

r - 为什么聚类图标签使用行而不是 ID 列中的名称?

excel - 在 Tkinter 中打开 excel 文件并绘制图形

python - 如何根据 Matplotlib 中的变量用颜色填充多边形?

java - 使用 Log4j2 2.11 的微秒级打印分辨率

php - mdate() 函数 codeigniter - 错误