options(width = 300) library(ggplot2) library(tidyr) # Create the RT column with values ranging from -20 to 40 RT <- seq(4, 10, by = 1) # Create the column names for Kz z_values <- seq(30, 50, by = 5) col_names <- paste0("K", z_values) # Create an empty dataframe with the desired columns df <- data.frame(RT = RT) # Loop through the z_values and calculate the Kz values using the formula for (z in z_values) { Kz <- (((273.15 + z) / ((273.15 + z) - (273.15 + df$RT))))*0.4 col_name <- paste0("K", z) df[col_name] <- Kz } # Print the resulting dataframe library(dplyr) # Replace negative values and infinite values with N/A df[, -1] <- df[, -1] %>% mutate_all(~ ifelse(. < 0 | !is.finite(.), NA, .)) df # Reshape the data into a longer format df_long <- df %>% gather(key = "K", value = "Value", -RT) # Convert K column values to numeric df_long$K <- as.numeric(gsub("K", "", df_long$K)) # Plot the line chart plot <- ggplot(df_long, aes(x = RT, y = Value, color = factor(K))) + geom_line() + labs(x = "RT", y = "Value", color = "K") + ylim(0, 6)+ # Set the y-axis limit to 15 scale_color_discrete(name = "K") # Save the plot as a PDF file ggsave("line_chart.pdf", plot, width = 8, height = 6)