我了解如何使用 geom_area 绘制日期时间变量。我尝试先转换为一个因子,然后再转换为一个数字,但是每次我都会收到此错误:
警告消息:在 max(ids, na.rm = TRUE) 中:max 没有非缺失参数;返回-Inf
如果有人可以帮助我,我将不胜感激!
我的日期时间变量是:“POSIXct”“POSIXt”和其他数字。
我的数据:
'data.frame': 96 obs. of 2 variables:
$ Date..GMT. : POSIXct, format: "1966-02-20 00:00:00" "1966-02-20 01:00:00" "1966-02-20 02:00:00" ...
$ Significant.Wave.Height.m.: num 3.04 3 2.98 2.97 2.97 3 3.03 3.08 3.14 3.21 ...
我的代码:
df1 %>% ggplot(aes(x = Date..GMT., y = Significant.Wave.Height.m.)) +
geom_line(size = 1, color = "#80A0C7") +
geom_area(fill = "#80A0C7") +
scale_y_continuous(breaks = seq(0, 7, 2),
limits = c(min_SigHeight, 7)) +
scale_x_datetime(labels = date_format("%d-%b"), date_breaks = "1 day") +
theme(panel.grid.major = element_line(size = 0.7, colour = '#D6E7EF'),
panel.background = element_rect(fill='white'),
panel.grid.minor = element_blank(),
axis.title.y = element_text(size = 20, color = "#80A0C7"),
axis.text.y = element_text(size = 24, color = "#80A0C7"),
panel.border = element_rect(colour = "black", fill=NA),
axis.text.x.bottom = element_text(angle = 30, color = "black", size = 24)) +
labs(y = expression(H[m0] (m)), x = "")