setwd("~/Documents/實驗設計")
doe1 = read.csv(file="doe1.csv",header=T)
doe2 = read.csv(file="doe2.csv",header=T)
doe3 = rbind(doe1,doe2)
colnames(doe3) = c("總分","濃度","口味","杯種","喜好程度")
doe3$喜好程度 = as.factor(doe3$喜好程度)
doe3$杯種 = as.factor(doe3$杯種)
levels(doe3$喜好程度)=c('喜愛','不喜愛')
levels(doe3$杯種)=c("馬丁尼杯","淺碟香檳杯")
doe3 %>% group_by(濃度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=reorder(濃度,desc(平均總分)),y=平均總分,fill=濃度))+geom_bar(stat='identity')+
labs(title ="滿意度vs濃度", x = "濃度", y = "平均總分")+
theme_gray(base_family="STHeiti")+
coord_cartesian(ylim = c(55,60))+theme(axis.text.x=element_text(angle=25,size=20),
axis.text.y=element_text(size=15),
axis.title.x=element_text(size=20),
axis.title.y=element_text(size=20),
plot.title = element_text(size = rel(2)))

doe3 %>% group_by(口味) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=reorder(口味,desc(平均總分)),y=平均總分,fill=口味))+geom_bar(stat='identity')+
labs(title ="滿意度vs口味", x = "口味", y = "平均分數")+
theme_gray(base_family="STHeiti")+
coord_cartesian(ylim = c(55,63))+theme(axis.text.x=element_text(angle=15,size=20),
axis.text.y=element_text(size=15),
axis.title.x=element_text(size=20),
axis.title.y=element_text(size=20),
plot.title = element_text(size = rel(2)))

doe3 %>% group_by(杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=reorder(杯種,desc(平均總分)),y=平均總分,fill=杯種))+geom_bar(stat='identity')+
labs(title ="滿意度vs杯種", x = "杯種", y = "平均分數")+
theme_gray(base_family="STHeiti")+
coord_cartesian(ylim = c(55,60))+theme(axis.text.x=element_text(angle=15,size=20),
axis.text.y=element_text(size=15),
axis.title.x=element_text(size=20),
axis.title.y=element_text(size=20),
plot.title = element_text(size = rel(2)))

doe3 %>% group_by(喜好程度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=reorder(喜好程度,desc(平均總分)),y=平均總分,fill=喜好程度))+geom_bar(stat='identity')+
labs(title ="滿意度vs喜好程度", x = "喜好程度", y = "平均分數")+
theme_gray(base_family="STHeiti")+
coord_cartesian(ylim = c(55,65))+theme(axis.text.x=element_text(angle=15,size=20),
axis.text.y=element_text(size=15),
axis.title.x=element_text(size=20),
axis.title.y=element_text(size=20),
plot.title = element_text(size = rel(2)))

doe3 %>% group_by(濃度,喜好程度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=濃度,y=平均總分,fill=喜好程度))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="濃度vs喜好程度", x = "濃度", y = "平均總分")

doe3 %>% group_by(濃度,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=濃度,y=平均總分,fill=杯種))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="濃度vs杯種", x = "濃度", y = "平均總分")

doe3 %>% group_by(口味,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=口味,y=平均總分,fill=杯種))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="口味vs杯種", x = "口味", y = "平均總分")

doe3 %>% group_by(口味,喜好程度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=口味,y=平均總分,fill=喜好程度))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="口味vs喜好程度", x = "口味", y = "平均總分")

doe3 %>% group_by(喜好程度,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=喜好程度,y=平均總分,fill=杯種))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="喜好程度vs杯種", x = "喜好程度", y = "平均總分")

doe3 %>% group_by(喜好程度,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=杯種,y=平均總分,fill=喜好程度))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="喜好程度vs杯種", x = "杯種", y = "平均總分")

doe3 %>% group_by(濃度,口味) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=濃度,y=平均總分,fill=口味))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="濃度vs口味", x = "濃度", y = "平均總分")

doe3 %>% group_by(濃度,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=杯種,y=平均總分,fill=濃度))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="杯種vs濃度", x = "杯種", y = "平均總分")

doe3 %>% group_by(濃度,喜好程度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=喜好程度,y=平均總分,fill=濃度))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="喜好程度vs濃度", x = "喜好程度", y = "平均總分")

doe3 %>% group_by(口味,杯種) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=杯種,y=平均總分,fill=口味))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="杯種vs口味", x = "杯種", y = "平均總分")

doe3 %>% group_by(口味,喜好程度) %>% summarise(平均總分=mean(總分)) %>%
ggplot(aes(x=喜好程度,y=平均總分,fill=口味))+geom_bar(stat='identity')+
theme_gray(base_family="STHeiti")+labs(title ="喜好程度vs口味", x = "喜好程度", y = "平均總分")
