# Load necessary libraries library(ggplot2) library(dplyr) # Create dataset for mks-5 mks_5 <- data.frame( Minus_1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), `0_second` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `50_second` = c(0.21, 0.31, 0.22, 0.15, 0.09, 0.20, 0.18, 0.12, 0.17, 0.10, 0.10, 0.10, 0.29, 0.34, 0.32, 0.19) ) # Create dataset for bbs-7 bbs_7 <- data.frame( Minus_1 = c(1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00), `0_second` = c(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00), `50_second` = c(0.05, 0.00, 0.04, 0.00, 0.02, 0.00, 0.00) ) # Convert column names to valid variable names names(mks_5) <- gsub("`", "_", names(mks_5)) names(bbs_7) <- gsub("`", "_", names(bbs_7)) # Function to calculate mean and SE summary_stats <- function(df) { data.frame( Time = c(-1, 0, 50), Mean = c(mean(df$Minus_1), mean(df$X0_second, na.rm = TRUE), mean(df$X50_second, na.rm = TRUE)), SE = c(sd(df$Minus_1)/sqrt(length(df$Minus_1)), sd(df$X0_second, na.rm = TRUE)/sqrt(length(df$X0_second)), sd(df$X50_second, na.rm = TRUE)/sqrt(length(df$X50_second))) ) } # Compute summary statistics for both datasets plot_mks_5 <- summary_stats(mks_5) %>% mutate(Dataset = "mks-5") plot_bbs_7 <- summary_stats(bbs_7) %>% mutate(Dataset = "bbs-7") # Combine both datasets combined <- rbind(plot_mks_5, plot_bbs_7) # Define custom colors my_colors <- c("red", "#006400") # Create a new column for labels combined$Label <- ifelse(combined$Dataset == "mks-5", "italic('mks-5')", "italic('bbs-7')") # Plot with error bars ggplot(combined, aes(x = Time, y = Mean, group = Dataset, color = Dataset)) + geom_smooth(method = "loess", se = FALSE, size = 1.3) + geom_point(size = 3) + geom_errorbar(aes(ymin = Mean - SE, ymax = Mean + SE), width = 2, size = 0.7) + scale_x_continuous(limits = c(-1, 50), name = "Time (s)") + scale_y_continuous(name = "Fluorescence Intensity") + theme(axis.line = element_line(color = "black", size = 1), axis.text = element_text(size = 16, color = "black", face = "bold"), axis.title = element_text(size = 16, color = "black", face = "bold"), panel.background = element_blank(), plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + scale_color_manual(values = my_colors) + guides(color = FALSE) + geom_text( data = subset(combined, Time == 50), aes(label = Label, color = Dataset), size = 5, fontface = "bold", position = position_nudge(y = -0.05), # Adjust vertical position hjust = 0.5, parse = TRUE # Enables italic formatting )