我正在使用fdc
. hydroTSM package
我有三个,我想data.frame
构建具有in和. 以下将产生for 。data.frame
facet_wrap
ggplot
plots
three rows
one column
FDC curves
DF1
library(tidyverse)
library(hydroTSM)
library(gridExtra)
DF1 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800))
DF2 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800))
DF3 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800))
fdc(DF1, plot = TRUE)
我尝试使用gridExtra package
withgrid.arrange
将三个图强制在一个数字上。我不仅没有做到这一点,而且它不是首选方法。我想facet_wrap
使用ggplot
. 事实上,这张图是用DF1
数据画错的。我正在寻找类似下面的东西:
更新:这是基于@Jon Spring 的建议。
graphics.off()
rm(list = ls())
library(tidyverse)
library(hydroTSM)
library(gridExtra)
DF1 = data.frame(Ob = runif(800,0,500), M1= runif(800,0,700), M2 = runif(800,2,800), df = rep("Upstream", 800))
DF2 = data.frame(Ob = runif(1000,0,500), M1 = runif(1000,0,700), M2 = runif(1000,2,800), df = rep("Midstream", 1000))
DF3 = data.frame(Ob = runif(1000,0,500), M1 = runif(1000,0,700), M2 = runif(1000,2,800), df = rep("Downstream", 1000))
# combine data into one table with id column for the source
bind_rows(DF1, DF2, DF3) %>%
# reshape into longer format
pivot_longer(-df, names_to = "src", values_to = "flow") %>%
arrange(-flow) %>%
group_by(df, src) %>%
mutate(flow_pct = 1 - percent_rank(flow)) %>%
ungroup() %>%
ggplot(aes(flow_pct, flow, color = src)) +
geom_line() +
theme_light() +
facet_wrap(~df, ncol = 1) +
labs(x = "% Time flow equalled or exceeded",
y = "Q, [m3/s]") +
theme(strip.text = element_text(hjust = 0, color = "black"),
strip.background = element_blank())