#------ Run all installed package in library
#lapply(.packages(all.available = TRUE), function(xx) library(xx,character.only = TRUE))
####################################################################
# Part-1 { Initial Working}
###################################################################
# set directory
setwd("D:/R_working/mango-madam")
data_mango=read.csv("data_1.csv",na="***")
data_mango=data.frame(data_mango)
#-- view structure of data
str(data_mango)
### conversion of treatments into factors
data_mango <- within(data_mango, {
treatment <- as.factor(treatment)
replication <- as.factor(replication)
})
str(data_mango)
#-- re-arrangement treatment levels for graphs
data_mango$treatment<- factor(data_mango$treatment, levels=levels(data_mango$treatment)[c(1,5,6,7,8,9,10,11,12,2,3,4)])
#-- mean and standard deviation calculations
mean_mango <- aggregate(.~treatment, FUN="mean", data=data_mango)
sd_mango <- aggregate(.~treatment, FUN="sd", data=data_mango)
#####################################################################
# Part-2 [Graphics part adjustment]
#####################################################################
#-- X and y-axis adjustment
s.theme <- theme(axis.text.x=element_text(size=18),axis.title.x=element_text(size=18),
axis.text.y=element_text(size=18),axis.title.y=element_text(size=18, face="bold"),
legend.text=element_text(size=18),
axis.ticks.length=unit(0.4, "cm"),legend.key.width=unit(0.4, "cm"),
legend.key.height=unit(0.8, "cm"), legend.position="right",
plot.margin = unit(c(1, 1, 1, 1), "lines"),
panel.grid.minor=element_blank())
pos <- 0.9
#-- adjust y-labels
labs <- c(list(biochar="Biochar",
fruit_weight=expression("Fruit Weight (g)"),
fruit_set=expression("Fruit Set (%)"),
yield=expression("Mango Yield (Kg plant"^-1*")"),
acidity=expression("Acidity (%)"),
volume=expression("Fruit Volume (cm"^-3*")"),
pn_photosynrhetic=expression('Photo synthetic rate (?mol CO'[2]*' m'^-2*' S'^-1*')'),
tdm=expression("Total dry matter (kg ha"^-1*")"),
Leaf_index=expression("Leaf Area Index (cm"^2*")")
))
#-- color selection
n=12
colr=rainbow(n); colt=terrain.colors(n); colc=cm.colors(n)
colh=heat.colors(n); colto=topo.colors(n)
#barplot(seq(1:12), col=topo.colors(12))
par(mfrow=c(2,3))
pie(rep(1,n), col=colr)
pie(rep(1,n), col=colt)
pie(rep(1,n), col=colc)
pie(rep(1,n), col=colh)
pie(rep(1,n), col=colto)
colors <- c(colr[8],colt[3],colt[9],colh[4],colto[7],colc[11], colto[3],colh[8],colto[6],colto[7],colto[4],colto[1])
#-- color by brewer function
display.brewer.all(colorblindFriendly = TRUE)
###################################################################
#-- Part-3 [Graphs]
###################################################################
#-- fruit weight
fruit_weight=ggplot(data=mean_mango ,aes(x=treatment, y=fruit_weight,
fill=factor(""))) + theme_bw() +
geom_bar(width=pos,position=position_dodge(pos),stat="identity")+
geom_errorbar(aes(ymin=mean_mango$fruit_weight-sd_mango$fruit_weight,ymax=mean_mango$fruit_weight+sd_mango$fruit_weight),
width=pos/2,
position=position_dodge(pos))+
xlab("") +
scale_y_continuous(limits = c(0, 550), breaks = seq(0, 550, by = 50)) +
ylab(labs$fruit_weight)+
s.theme+
labs(fill = "Treatment")+
theme(legend.position = "")+
scale_fill_brewer(palette="Paired")
fruit_weight
ggsave("p2_fruit_weight.png", width = 12, height = 7)
###############################################################
#---------- Saving all session
################################################################
save(list = ls(all=TRUE), file= "D:/R_working/mango-madam//session1")
load(file= "D:/R_working/mango-madam/session1")

No comments:
Post a Comment