Skip to content

Commit

Permalink
Graphs read from correct locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemuk committed Jan 30, 2025
1 parent 01f020e commit bc95d0e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
9 changes: 5 additions & 4 deletions R/simulation_epigeopop.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ run_complete_simulation <- function(output_dir="data/Andorra/simulation_outputs"
sir_plot <- create_sir_plot(df_long, display = TRUE)
save_sir_plot(sir_plot, file.path(output_dir, sir_plot_file))

# Generate Rt plot
rt_plot <- plot_rt_curves(file.path(output_dir, "secondary_infections.csv"), location = file.path(output_dir, rt_plot_file))

plot_rt_curves("data/Andorra/simulation_outputs/secondary_infections.csv")

create_serial_interval_plot("data/Andorra/simulation_outputs/serial_intervals.csv", display = TRUE)
# Generate Serial Interval plot
si_plot <- create_serial_interval_plot(file.path(output_dir, "serial_intervals.csv"), display = TRUE, location = file.path(output_dir, si_plot_file))

return(list(simulation = sim, data = df_long, sir_plot = sir_plot, rt_plot = "", si_plot = ""))
return(list(simulation = sim, data = df_long, sir_plot = sir_plot, rt_plot = rt_plot, si_plot = si_plot))
}

results <- run_complete_simulation()
6 changes: 4 additions & 2 deletions R/simulation_toy.r
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ run_complete_simulation <- function(output_dir="data/toy/simulation_outputs",
save_sir_plot(sir_plot, file.path(output_dir, sir_plot_file))


plot_rt_curves("data/simulation_outputs/secondary_infections.csv")
# Generate Rt plot
rt_plot <- plot_rt_curves(file.path(output_dir, "secondary_infections.csv"), display =TRUE, location = file.path(output_dir, rt_plot_file))

create_serial_interval_plot("data/simulation_outputs/serial_intervals.csv", display = TRUE)
# Generate Serial Interval plot
si_plot <- create_serial_interval_plot(file.path(output_dir, "serial_intervals.csv"), display = TRUE, location = file.path(output_dir, si_plot_file))

return(list(simulation = sim, data = df_long, sir_plot = sir_plot, rt_plot = "", si_plot = ""))
}
Expand Down
15 changes: 3 additions & 12 deletions R/wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ create_sir_plot <- function(df_long, title = "SIR Model Flow", display = TRUE) {
}

# Save plot
save_sir_plot <- function(plot, filename, width = 10, height = 6, dpi = 300) {
ggsave(
filename = here(filename),
plot = plot,
width = width,
height = height,
dpi = dpi
)
}

save_sir_plot <- function(plot, filename, width = 10, height = 6, dpi = 300) {
ggsave(
Expand All @@ -173,7 +164,7 @@ save_sir_plot <- function(plot, filename, width = 10, height = 6, dpi = 300) {
)
}

plot_rt_curves <- function(file_path) {
plot_rt_curves <- function(file_path, location) {
# Check if file exists
if (!file.exists(file_path)) {
stop("The file does not exist. Please provide a valid file path.")
Expand Down Expand Up @@ -216,7 +207,7 @@ plot_rt_curves <- function(file_path) {
}

# Create serial interval plot
create_serial_interval_plot <- function(file_path, title = "Serial Interval Distribution", display = TRUE) {
create_serial_interval_plot <- function(file_path, title = "Serial Interval Distribution", display = TRUE, location) {
# Read the CSV file and exclude the first row
data <- read.csv(file_path, header = TRUE)[-1, ]

Expand Down Expand Up @@ -245,7 +236,7 @@ create_serial_interval_plot <- function(file_path, title = "Serial Interval Dist
}

# Save the plot
save_sir_plot(p, "data/simulation_outputs/serial_interval.png")
save_sir_plot(p, location)

return(p)
}
Binary file modified data/simulation_outputs/rt_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/toy/simulation_outputs/SIR_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bc95d0e

Please sign in to comment.