forked from eliminaterabies/egfR0
/
rplot_combo.R
40 lines (33 loc) · 1.07 KB
/
rplot_combo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
library(dplyr, warn.conflicts=FALSE)
library(ggplot2); theme_set(theme_bw())
library(forcats)
library(shellpipes)
startGraphics()
dat <- (bind_rows(rdsReadList())
|> left_join(tsvRead(),by=c("loc"="varname"))
%>% mutate(loc_final = ifelse(loc == "Tokyo1", "Tokyo",loc)
, loc_final = ifelse(loc_final == "Tokyo2", "Tokyo",loc_final)
, loc_final = paste0(loc_final, "\n", year)
)
# rbind(readRDS("exp.egf_single.rds"),readRDS("logistic.egf_single.rds"))
## |> mutate(loc = factor(loc, levels=rev(levels(loc))))
)
print(dat)
print(
ggplot(dat)
+ aes(
# to simply reverse:
# x=forcats::fct_rev(loc)
# This is reordering by the first est for each loc:
# x = forcats::fct_reorder(loc, est)
# This is reordering by the mean est:
x = forcats::fct_reorder(loc_final, est, .fun = mean)
, y=est, color=phase)
+ geom_pointrange(aes(ymin=lwr,ymax=upr,lty=method)
, position = position_dodge(width=-0.4)
)
+ scale_linetype_manual(values=c("dotted","solid"))
+ coord_flip()
# note that x and y are switched!
+ labs(y = "r (1/month)", x = NULL)
)