setwd("C:/Users/User7/Desktop/data")

data <- read.csv('la1.csv', header = T, sep = ',')

df <- data.frame(
  ID = c('I1', 'I2', 'I3', 'I4', 'I5'),
  Rest = c(1.5, 1.6, 1.7, 1.5, 1.4),
  Warm_up = c(1.7, 1.8, 1.8, 1.6, 1.5),
  Post_exercise = c(8.9, 9.0, 9.1, 9.3, 9.0),
  Post_intervention = c(2.5, 2.6, 2.7, 2.6, 2.5),
  Post_20min_resting = c(1.8, 1.9, 2.0, 1.9, 1.8)
)


df$Warm_up_decrease <- df$Warm_up - df$Rest
df$Post_exercise_decrease <- df$Post_exercise - df$Rest
df$Post_intervention_decrease <- df$Post_intervention - df$Rest
df$Post_20min_resting_decrease <- df$Post_20min_resting - df$Rest


df$Warm_up_percentage <- (df$Warm_up_decrease / df$Rest) * 100
df$Post_exercise_percentage <- (df$Post_exercise_decrease / df$Rest) * 100
df$Post_intervention_percentage <- (df$Post_intervention_decrease / df$Rest) * 100
df$Post_20min_resting_percentage <- (df$Post_20min_resting_decrease / df$Rest) * 100


mean_decrease <- data.frame(
  Condition = c('Warm up', 'Post-exercise', 'Post-intervention', 'Post-20min resting'),
  Percentage_decrease = c(mean(df$Warm_up_percentage),
                          mean(df$Post_exercise_percentage),
                          mean(df$Post_intervention_percentage),
                          mean(df$Post_20min_resting_percentage))
)


library(ggplot2)
## Warning: 패키지 'ggplot2'는 R 버전 4.3.3에서 작성되었습니다
ggplot(mean_decrease, aes(x = Condition, y = Percentage_decrease, fill = Condition)) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = paste0(round(Percentage_decrease, 2), "%")), vjust = -0.5, size = 4) +
  labs(title = "시간대별 젖산 감소율 (%) (기준: 휴식)", 
       x = "시간대", 
       y = "평균 젖산 감소율 (%)") +
  theme_minimal() +
  theme(legend.position = "none")