【发布时间】:2021-10-27 11:01:15
【问题描述】:
我有这样的数据:
| datetime | aws.pr_sum | aws.ta_2m | timestamp |
|---|---|---|---|
| 2020-06-14 12:00:00 | 0.00 | 19.20000 | 1635171717 |
| 2020-06-14 13:00:00 | 0.85 | 19.73833 | 1635171717 |
| 2020-06-14 14:00:00 | 0.00 | 21.95667 | 1635171717 |
| 2020-06-14 15:00:00 | 0.00 | 21.71333 | 1635171717 |
| 2020-06-14 16:00:00 | 0.00 | 21.04667 | 1635171717 |
| 2020-06-14 17:00:00 | 0.00 | 20.66500 | 1635171717 |
正如标题所说,我想在同一张图中绘制每日累积降水量和每日每小时降水量。我做什么:
df <- df %>% group_by(timestamp) %>%
mutate(aws_pcp_cumulative = cumsum(aws.pr_sum))
c3 <- c("inca" = "#6aa6fa", "AWS" = "#2ECBE9")
p3 = ggplot(df, aes(x=datetime)) +
geom_bar(stat = "identity", aes(x = datetime + shift/2, y = aws.pr_sum, color="AWS"), size=0.7, fill=NA, width=wd ) +
geom_line(data = df, aes(x = datetime, y = aws_pcp_cumulative, color = "AWS"), size=1.2,alpha=0.2) +
geom_bar(stat = "identity", aes(x = datetime - shift/2, y = inca.RR.max, color="inca"), size=0.7, fill=NA, width=wd) +
geom_line(data = df, aes(x = datetime, y = inca_pcp_cumulative, color = "inca"), size=1.2,alpha=0.2) +
geom_text(aes(label=laws, x = datetime, y = aws.pr_sum, color="AWS"), vjust = -0.5, size=3) +
geom_text(aes(label=linca, x = datetime, y = inca.RR.max, color="inca"), vjust = -0.5, size=3) +
scale_x_datetime(breaks=brks, labels = lbls, date_labels="%d.%m %H:%M") +
labs(x="",
y= "",
color="zrážky [mm/h]") +
scale_color_manual(values = c3) +
theme(
panel.grid.major.x = element_blank(),
legend.position = c(0.01,0.95),
legend.justification = c("left", "top"),
legend.box.just = "left",
legend.margin = margin(6, 30, 6,6),
legend.title = element_text(size = 12))
这是结果:https://imgur.com/a/MYmJhy7
正如我们所见,整个期间都会累积总和,但我希望每天计算一次。有什么想法吗?
【问题讨论】: