rm(list=ls())
# Load necessary libraries
#install.packages(c("ggplot2", "dplyr"))
library(ggplot2)
library(dplyr)

# Number of data points (e.g., number of days)
n <- 180  # For a 6-month period

# Simulating data for number of mutations
# Assuming a linear increase in mutations over the 6 months
slope <- 0.05  # Arbitrary slope value
mutations <- seq(0, slope * n, length.out=n)

# Simulating data for logistic growth rate of the virus
# Parameters for logistic growth
K <- 1000  # Carrying capacity
r <- 0.03  # Growth rate
P0 <- 1    # Initial number of cases

time <- seq(1, n)
logistic_growth <- K / (1 + (K - P0) / P0 * exp(-r * time))

# Combine data into a data frame for plotting
data <- data.frame(
  Time = time,
  Mutations = mutations,
  LogisticGrowth = logistic_growth
)

# Plot using ggplot2
p1<-ggplot(data, aes(x=Time)) + 
  geom_line(aes(y=Mutations, color="Number of Mutations")) +
  geom_line(aes(y=LogisticGrowth, color="Logistic Growth Rate")) +
  labs(title="Simulated SARS-CoV-2 Data",
       y="Value") +
  scale_color_manual(values=c("red", "blue"))+
  theme(legend.position="top")


# Plot using ggplot2
p2<-ggplot(data, aes(x=Mutations,y=LogisticGrowth)) + 
  labs(title="Simulated SARS-CoV-2 Data",
  y="Logistic Growth Rate",x="Number of Mutations")+
  geom_point(alpha=0.6) +
  theme_minimal()


gridExtra::grid.arrange(p1,p2,nrow=1)
