library(readxl)
## Warning: package 'readxl' was built under R version 4.0.3
Diet=read_excel("C:/Users/Admin/Desktop/Thesis Proposal/Diet.xlsx",sheet = "Sheet2", range = "L5:N30")
View(Diet)
attach(Diet)
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.0.3
#Xử lý data #level_order=c(“Protein”,“Fat”,“Energy”,“DM”,“Ash”) => Thứ tự mong muốn
level_order=c("Protein","Fat","Energy","DM","Ash")
g=ggplot(Diet,aes(x = factor(Parameter,level_order),y=Value,fill=Treatment))
#Vẽ đồ thị
#Gán đối tượng màu sắc kích thước tên là "David"
David <- element_text(face = "bold", color = "black", size = 11)
#Chức năng identity là lấy y bằng cột value trong file excel
#Chức năng position là tách làm 5 cột (5 parameter), nếu ko sẽ vẽ cột chồng
g+geom_bar(stat = "identity",position=position_dodge(width=0.9))+
theme_bw()+
theme_classic()+
#scale_fill_manual điều chỉnh màu nghiệm thức theo ý muốn
scale_fill_manual("Treatment", values = c("High_Pro" = "Red", "High_Fat" = "Yellow", "Mix" = "Black","Initial"="pink","High_Carb"="blue"))+
xlab("Parameter")+
#Cách ghi lên xuống
ylab(bquote(g.kg[-1]^-1))+
theme(plot.title = element_text(face = "bold",hjust = 0.5))+
labs(title = "EFFECT OF MACRONUTRIENTS ON SNAKEHEAD GROWTH",subtitle = "BAR CHART FOR ILLUSTRATION",caption = "Data source: David La")+
theme(axis.text.x = David)+
theme(axis.text.y = David)+
scale_y_continuous(breaks=c(0,50,100,150,200,250,300,350),limits=c(0,350))+
theme(plot.caption = element_text(hjust = 0, face = "italic",color="pink"),plot.title = element_text(color="pink",hjust = 0.5, size = 14),plot.subtitle=element_text(color="pink",size=11))