,例如,考虑此示例代码:
library(ggplot2)
exp<-data.frame(
date = c(rep("2025-02-01", 13), rep("2025-02-02", 13),rep("2025-02-03", 13)),
hour = rep(seq(6, 18, 1),3),
obs = runif(13*3, min=1, max=50)
)
exp |>
mutate(
date.hour = factor(paste0(date, " ", hour, " hour"), levels=unique(paste0(date, " ", hour, " hour")), ordered=TRUE)
) |>
ggplot(aes(x=date.hour, y=obs, group=1)) +
geom_line() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
nove,我想知道的是,是否可以跨越整个小时的日期,以创建一个看起来像这样的图:
使用
legendry
包装,您可以轻松地使用
guide_axis_nested