library(readr)
library(tidyr)
library(dplyr)
## 
## 載入套件:'dplyr'
## 下列物件被遮斷自 'package:stats':
## 
##     filter, lag
## 下列物件被遮斷自 'package:base':
## 
##     intersect, setdiff, setequal, union
library(psych)
library(ggplot2)
## 
## 載入套件:'ggplot2'
## 下列物件被遮斷自 'package:psych':
## 
##     %+%, alpha
#去除不要的row
#改變fj的內容
#如果回答跟預測一樣就會得1分
n60 <- read.csv('FillerAnalysis(n60).csv', header = T, sep = "," )
filtered_n60 <- n60[-which(n60$Procedure.Block. == "InterimBreak"), ]
filler_n60 <- filtered_n60 %>% filter(IntentionType=="Filler") %>% mutate(AnswerOption = case_when(TargetS.RESP=="f"~"wei", TargetS.RESP=="j"~"bie")) %>% mutate(PreAns = case_when(PredictedAnswer=="未"~"wei", PredictedAnswer=="別"~"bie"))
fillerValue_n60 <- filler_n60 %>% mutate(Value = ifelse(AnswerOption==PreAns, 1, 0))
#計算正確率,以Subject分組
fillerSummary_n60 <- fillerValue_n60 %>% group_by(Subject) %>% summarise(count = sum(Value), percentage = round(count/120*100, 2)) %>% ungroup()
windowsFonts(A = windowsFont("微軟正黑體"))

fillerPlot_n60 <- ggplot(fillerSummary_n60, aes(x = Subject, y = percentage)) +
  stat_summary(fun = "identity", geom = "bar", width = 0.6, fill="#2297E6")+
  geom_text(aes(label = paste0(percentage, "%"), vjust = 0.4, hjust = -0.1), size =2.7) +
  coord_cartesian(ylim=c(0, 100)) +
  guides(fill="none") +
  geom_hline(yintercept=80,linetype="twodash",colour="red",size = 1) +
  coord_flip()+
  xlab("參與者") +
  ylab("百分比") +
  theme(axis.title.y =element_text(hjust = 0.5,angle=90,size=16, family = "A"))+
  theme(axis.title.x =element_text(hjust = 0.5,angle=360,size=16, family = "A"))+
  theme(axis.text.y=element_text(face="bold",size=12,color="#333333",family = "A"))+
  theme(axis.text.x=element_text(face="bold",size=12,color="#333333",family = "A"))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.
fillerPlot_n60