我想创建一个自定义 x 轴标签,就像在这里完成的那样: http ://blog.earlh.com/index.php/2009/07/plotting-with-custom-x-axis-labels-in- r-part-5-in-a-series/
但是当我试图设置 x 轴标签时:
at <- format(SubDateTime$DateTime, "%H") %in% c("00", "06", "12", "18")
axis(side = 1,at = SubDateTime$DateTime[at],
labels = format(SubDateTime$DateTime[at], "%a-%H"))
我收到以下错误:
Error in axis(side = 1, at = SubDateTime$DateTime[at],
labels = format(SubDateTime$DateTime[at],
: (list) object cannot be coerced to type 'double'
SubDateTime$DateTime 是一个具有两个日期(2013-06-01 和 2013-06-02)和每小时时间的 POSIXlt 类。我想在 x 轴上添加“Sun-00”、“Sun-06”、“Sun-12”等。
令我困惑的是,当我从上面的链接中执行示例时,它工作正常。
谢谢
编辑:
plot(x = SubDateTime$DateTime,
y = SubConsumption$Load.MW,
type = "l",
lwd = 2,
ylim = c(0, max(SubConsumption$Load.MW, na.rm = FALSE)*1.2),
main = "Spot Price June 01 to June 02",
xlab = "",
ylab = "",
bty = "l",
xaxt = "n")
您需要有关 SubDateTime$DateTime 的哪些信息?