【发布时间】:2021-11-20 02:49:00
【问题描述】:
我想创建一个速度时间序列图,类似于之前在此线程中提出的问题:Stick Plot for wind speed and direction data in ggplot
我尝试使用我的数据进行绘图,但出现错误提示
“错误:输入无效:date_trans 与 Date 类的对象一起使用 只有。”
谁能帮我解决这个问题?我对 R 编程很陌生,所以它真的对我有很大帮助。这是我的脚本:
Speed <-c(24,23,23,24,26,27,27,27,26,24)
Dir <- c(108,105,103,100,97,96,97,99,101,103)
Date <-c(2016-08-01,2016-08-02,2016-08-3,2016-08-4,2016-08-5,2016-08-6,2016-09-7,2016-09-8,2016-09-9,2016-09-10)
DF <-data.frame(Speed,Dir,Date)
DF$Date <- as.Date(1,as.Date(DF$Date,origin = "2016-08-04"))
ggplot(DF) +
geom_segment(aes(x = Date,
y = 0,
xend = Date + lubridate::dhours(Speed * 1 * -cos((90-Dir) / 360 * 2 * pi)),
yend = Speed * 1 * -sin((90-Dir) / 360 * 2 * pi),
col = factor(Date)
),
arrow = arrow(length = unit(0.5, "cm")) ) +
geom_point(aes(Date, 0), size = 1) +
scale_x_date(labels = date_format('%b'), breaks = date_breaks('1 month'))+
coord_fixed(3600) +
theme(legend.position = "none")+
geom_rect(aes(xmin = as.Date("016-08-04", "%Y-%m-%d"),
xmax = as.Date("2016-09-18", "%Y-%m-%d"),ymin = -Inf,ymax = Inf))
【问题讨论】:
-
你的约会日期真的是这样吗?因为
x <-2016-08-01只返回 2007。这只是数字的减法。你的意思是把它们放在引号里吗?喜欢Date <- c("2016-08-01", "2016-08-02", ...)?
标签: r ggplot2 time-series