Steps taken:
Read the CSV file. Prompt the user for the Specification Limit and Standard Deviation.
Filter the data for each unique combination of Temperature and Humidity.
Set the standard deviation and specification limit
Plot the data with error bars, a line of best fit, and the specification limit.
Calculate and plot the isoconversion point.
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Read the data
data <- read.csv("Degradant 10.csv")
# Prompt user for Specification Limit and Standard Deviation
spec_limit <- 0.3
std_dev_percent <- 0.1
# Filter data for a unique combination of Temperature and Humidity for Plot A
plot_a_data <- data %>% filter(Plot == 'C', !is.na(T), !is.na(RH))
# Calculate error bars as specified percentage of the degradant value
plot_a_data = plot_a_data %>%
mutate(error = X..Degradant * std_dev_percent)
# Create the plot with ggplot2
p <- ggplot(plot_a_data, aes(x=Days, y=X..Degradant)) +
geom_point() +
geom_errorbar(aes(ymin=X..Degradant-error, ymax=X..Degradant+error), width=0.1) +
geom_smooth(method="lm", color="darkgreen", se=FALSE) +
geom_hline(yintercept=spec_limit, color="orange", linetype="dashed") +
annotate("text", x = Inf, y = spec_limit, label = "Specification Limit", hjust = 1.1, vjust = 0, color="black") +
labs(title=paste('Degradant vs Time; T=', unique(plot_a_data$T), ', RH=', unique(plot_a_data$RH)),
x='Time (days)', y='% Degradant') +
theme_minimal()
# Print the plot
print(p)
## `geom_smooth()` using formula = 'y ~ x'
# Calculate the isoconversion point using the linear model
model <- lm(X..Degradant ~ Days, data=plot_a_data)
isoconversion_time <- (spec_limit - coef(model)[1]) / coef(model)[2]
# Add vertical line for isoconversion time if it's within the range of data
if (!is.na(isoconversion_time) && isoconversion_time > min(plot_a_data$Days) && isoconversion_time < max(plot_a_data$Days)) {
p <- p + geom_vline(xintercept=isoconversion_time, color="purple", linetype="dashed") +
annotate("text", x = isoconversion_time, y = Inf, label = paste("Isoconversion Time:", round(isoconversion_time, 2), "Days"), hjust = 1.1, vjust = 1.1, color="purple")
print(p)
cat("Isoconversion Time:", isoconversion_time, "Days\n")
} else {
cat("Isoconversion point is not within the range of the data\n")
}
## `geom_smooth()` using formula = 'y ~ x'
## Isoconversion Time: 37.18535 Days