library(deSolve) library(ggplot2) # Define the ODE system ode_system <- function(t, y, parms) { with(as.list(c(y, parms)), { dydt <- r * y * (1 - y/K) return(list(dydt)) }) } # Define the initial conditions and parameters y0 <- c(y = 1) parms <- c(r = 0.1, K = 10) # Define the time span times <- seq(0, 50, by = 0.1) # Solve the ODE system using the "ode" solver out <- ode(y = y0, times = times, func = ode_system, parms = parms) # Convert the output to a data frame df <- as.data.frame(out) # Create a plot using ggplot2 p <- ggplot(df, aes(times, y)) + geom_line() + labs(title = "Logistic Growth Model", x = "Time", y = "Population Size") # Save the plot as a PDF file ggsave("logistic_growth.pdf", p)