gpt4 book ai didi

r - 在 r 中绘制日期

转载 作者:行者123 更新时间:2023-12-04 11:28:58 24 4
gpt4 key购买 nike

我写了下面的绘图命令:

Stripped_DATA <- structure(list(Epoch = structure(c(1110925802, 1110929408, 1110933014, 
1110936616, 1110940217),
class = c("POSIXct", "POSIXt"),
tzone = "Europe/Helsinki"),
Timediff = c(-1.4653909261659, -1.46512243581845,
-1.46505141447328, -1.46503418192427, -1.46464648029912)),
.Names = c("Epoch", "Timediff"),
row.names = c("11070", "21070", "31070", "41070", "51070"),
class = "data.frame")

plot(Stripped_DATA, main = "Maser-69 hourly averages raw data, -3 < 3 microseconds", xlab = "Date", ylab = "microseconds")
ticks <- seq(as.POSIXct("2005-03-16 00:30:02", format = "%F %T"),
as.POSIXct("2019-04-19 14:29:55", format = "%F %T"), by = "4 months")
labels <- seq(as.Date("2005-03-16"), as.Date("2019-04-19"), by = "4 months")
axis.POSIXct(1, at = ticks, format = "%Y-%m-%d %H", labels = labels)

给出图中显示的 x 轴。如何消除与日期重叠的三个年度刻度?另外,有没有办法将日期标签从水平变为垂直,以便我可以添加更多日期标签?

enter image description here

最佳答案

如果您只想使用您的刻度,请在使用 xaxt='n' 绘制之前从您的绘图中删除标签,并使用 las=2 旋转您的绘图标签

   plot(Stripped_DATA, main = "Maser-69 hourly averages raw data, -3 < 3 microseconds",
xlab = "Date", ylab = "microseconds" , las=2, xaxt="n")
ticks <- seq(as.POSIXct("2005-03-16 00:30:02", format = "%F %T"),
as.POSIXct("2019-04-19 14:29:55", format = "%F %T"), by = "4 months")
labels <- seq(as.Date("2005-03-16"), as.Date("2019-04-19"), by = "4 months")
axis.POSIXct(1, at = ticks, format = "%Y-%m-%d %H", labels = labels, las=2)

plot

说明:您的 axis.POSIct() 函数添加了额外的标签。这些可以与您的绘图标签重叠并创建您显示的输出。所以不要用 xaxt='n'

绘制原始标签

请注意,这只是如果您只想拥有 axis.POSIXct 标签

关于r - 在 r 中绘制日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56201259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com