R/dynamics_relevant_functions.R
plot_population_history.RdCreates a ggplot visualization of clone population dynamics over time from simulation results produced by the simulate_sc_dynamics function.
plot_population_history(
simulation_result,
clone_colors,
title = "Population History"
)A ggplot object displaying population dynamics over time with customized styling
This function transforms the population history data from wide to long format and creates a line plot showing how the population of each clone type changes over time. The plot includes custom styling for readability and aesthetic presentation.
The time points displayed on the x-axis correspond to the simulation steps without displaying the raw time values (using discrete scale with no labels).
# Define colors for each clone type
clone_colors <- c(A = "blue", B = "red")
# Create and display the plot
p <- plot_population_history(sim_result, clone_colors, "Clone Evolution")
#> Warning: restarting interrupted promise evaluation
#> Warning: internal error -3 in R_decompress1
#> Error: lazy-load database '/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/cancerSimCraft/R/cancerSimCraft.rdb' is corrupt
print(p)
#> Error: object 'p' not found
# Save the plot
ggsave("population_dynamics.png", p, width = 8, height = 6)
#> Error in ggsave("population_dynamics.png", p, width = 8, height = 6): could not find function "ggsave"