/
plot-sir.R
51 lines (42 loc) · 1.56 KB
/
plot-sir.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
40
41
42
43
44
45
46
47
48
49
50
51
## SKG
## Plotting SIR functions and themes
## March 6, 2019 Ash Wednesday. Truly this is penance
#' Plot the t, X simulations
#'
#' @param catalyst_sims output from am_sir()
#' @param K number of total states
#' @param col_pal color palette of length K
#' @param states state names
#' @param xlab label for x
#' @param ylab label for y
#' @param title title
#' @param beta between 0 and 1
#' @param between 0 and 1
#' @param N total number of agents
#' @param L total number of runs
#' @param T total time steps
#' @param pretty logical. Default is TRUE
#' @return ggplot graph
plot_sims <- function(catalyst_sims, K = 3,
col_pal = c("blue", "red", "yellow3"),
states = c("S", "I", "R"),
xlab = "Time",
ylab = "% of Individuals",
title = "SIR Simulations",
beta = .1,
gamma = .03,
N = 1000,
L = 100,
T = 100,
pretty = TRUE
){
df <- as.data.frame(sims$X_mat)
dfm <- reshape2::melt(df, id.vars = c("t", "ll"))
g <- ggplot2::ggplot(dfm, ggplot2::aes(x = t, y = value,
group = paste(ll, variable),
col = variable)) +
ggplot2::geom_line() +
ggplot2::scale_color_manual(values = col_pal, labels = states)
g
return(g)
}