R Markdown

library(readr)
production <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Production/production.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   country = col_character(),
##   production = col_double(),
##   crop = col_character()
## )
View(production)
attach(production)
## The following object is masked _by_ .GlobalEnv:
## 
##     production
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.3
library(patchwork)
## Warning: package 'patchwork' was built under R version 4.1.1
library(ggsignif)
## Warning: package 'ggsignif' was built under R version 4.1.2
library(ggpubr)
library(agricolae)
library(easynls)
library(MVN)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## sROC 0.1-2 loaded
#############################

Production

ea<-subset(production, region=="Eastern Africa")
g1<-ggplot(ea, aes(x=period, y=production, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Production (million tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))+ theme(legend.position = "bottom")
g1

######################################
## Gnuts East Africa
gnuts_ea<-subset(production, region=="Eastern Africa" & crop=="Groundnut")

a1<-ggplot(gnuts_ea, aes(x= period, y=production)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Groundnut production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.

## Warning: Please use the `linewidth` argument instead.
 a1

 ## Gnuts in East Africa Line Graph
 
########## Maize
 gnuts_ea_1<-subset(production, region=="Eastern Africa" & crop=="Maize")

a2<-ggplot(gnuts_ea_1, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Maize production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 a2

########## Millet
 gnuts_ea_2<-subset(production, region=="Eastern Africa" & crop=="Millet")

a3<-ggplot(gnuts_ea_2, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Millet production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 a3

 ########## Sorghum
 gnuts_ea_3<-subset(production, region=="Eastern Africa" & crop=="Sorghum")

a4<-ggplot(gnuts_ea_3, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Sorghum production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 a4

West Africa

wa<-subset(production, region=="West Africa")

w1<-ggplot(wa, aes(x=period, y=production, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Production (million tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))+ theme(legend.position = "bottom")
w1

wst_1<-subset(production, region=="West Africa" & crop=="Groundnut")

b1<-ggplot(wst_1, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Groundnut production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 b1

 ####################### Maize
 wst_2<-subset(production, region=="West Africa" & crop=="Maize")

b2<-ggplot(wst_2, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Maize production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 b2

 #####################
 
 
 
 
####################### Millet
 wst_3<-subset(production, region=="West Africa" & crop=="Millet")

b3<-ggplot(wst_3, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Millet production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 b3

 ####################### Sorghum
 wst_4<-subset(production, region=="West Africa" & crop=="Sorghum")

b4<-ggplot(wst_4, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Sorghum production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 b4

 ########################

East and West Africa Total Production

ew_1<-subset(production, country== "Total W.A")

z1<-ggplot(ew_1, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Total production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~crop, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Total Production:West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

z1

######## EA
ew_2<-subset(production, country== ".Total E.A")

z2<-ggplot(ew_2, aes(x= period, y=production,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Total production (million tonnes)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =production), color = "black", size = 2,vjust=-0.5)+ facet_wrap(~crop, ncol=2)+ theme(legend.position = "none") +
  ggtitle("Total Production:Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

z2

Yield

yield <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Yield/yield.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   country = col_character(),
##   yield = col_double(),
##   crop = col_character()
## )
View(yield)
attach(yield)
## The following object is masked _by_ .GlobalEnv:
## 
##     yield
## The following objects are masked from production:
## 
##     country, crop, period, region
############ East Africa
ea_yld<-subset(yield, region=="Eastern Africa")

y1<-ggplot(ea_yld, aes(x=period, y=yield, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Yield (Mt/Ha)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))+ theme(legend.position = "bottom")
y1

################# West Africa
ea_yld_2<-subset(yield, region=="West Africa")

y2<-ggplot(ea_yld_2, aes(x=period, y=yield, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Yield (Mt/Ha)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))+ theme(legend.position = "bottom")
y2

####
#da=y1+y2+plot_layout(ncol = 1)
#ggsave("Yield_EA_WA_v1.pdf",da, width = 6, height =6, dpi=700)

################
## Gnuts East Africa
gnts<-subset(yield, region=="Eastern Africa" & crop=="Groundnut")

x1<-ggplot(gnts, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Groundnut Yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x1

########## Maize
 mz<-subset(yield, region=="Eastern Africa" & crop=="Maize")

x2<-ggplot(mz, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Maize yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x2

########## Millet
 millet<-subset(yield, region=="Eastern Africa" & crop=="Millet")

x3<-ggplot(millet, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Millet yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x3

 ########## Sorghum
 sorg<-subset(yield, region=="Eastern Africa" & crop=="Sorghum")

x4<-ggplot(sorg, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Sorghum yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=3)+ theme(legend.position = "none") +
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x4

Crop Yield West Africa

## Gnuts west Africa
gnts<-subset(yield, region=="West Africa" & crop=="Groundnut")

x1<-ggplot(gnts, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Groundnut yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x1

########## Maize
 mz<-subset(yield, region=="West Africa" & crop=="Maize")

x2<-ggplot(mz, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Maize yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x2

########## Millet
 millet<-subset(yield, region=="West Africa" & crop=="Millet")

x3<-ggplot(millet, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Millet yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x3

 ########## Sorghum
 sorg<-subset(yield, region=="West Africa" & crop=="Sorghum")

x4<-ggplot(sorg, aes(x= period, y=yield,fill=period)) +
geom_bar(stat="identity", color="black", position=position_dodge(),fill="blue")+
  xlab("")+
  ylab("Sorghum yield (Mt/Ha)")+
  theme_bw()+
  theme(plot.title=element_text(size=8,face="bold"),
        axis.text.x=element_text(angle=45,hjust=1,size=7,color="black"),
        axis.text.y=element_text(size=9,color="black"))+
theme(legend.background = element_rect(fill="white", size=0.5, linetype="solid", 
                                  colour ="black"))+
  geom_text(aes(label =yield), color = "black", size = 2.5,vjust=-0.5)+ facet_wrap(~country, ncol=2)+ theme(legend.position = "none") +
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))

 x4

burkina <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/burkina.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(burkina)
attach(burkina)
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
cols <- c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green")

Burkina Faso Calorie Consumption

p1 <- ggplot(data = burkina, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Burkina Faso")+
  theme(plot.title = element_text(hjust = 0.5))
 
p1

#+ scale_fill_discrete(breaks=c(“Yams”, “Sorghum and products”, “Rice (milled equivalent)”, “Potatoes”, “Millet and products”, “Maize and products”, “Cassava”,“Bananas”,“Plantains”))

Tanzania Calorie Consumption

tanzania <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/tanzania.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(tanzania)
attach(tanzania)
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p2 <- ggplot(data = tanzania, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Tanzania")+
  theme(plot.title = element_text(hjust = 0.5))
 
p2

Ethiopia Calorie Consumption

ethiopia <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/ethiopia.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(ethiopia)
attach(ethiopia)
## The following objects are masked from tanzania:
## 
##     calorie, crop, period, region
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p4 <- ggplot(data = ethiopia, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Ethiopia")+
  theme(plot.title = element_text(hjust = 0.5))
 
p4

Ghana Calorie Consumption

ghana <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/ghana.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(ghana)
attach(ghana)
## The following objects are masked from ethiopia:
## 
##     calorie, crop, period, region
## The following objects are masked from tanzania:
## 
##     calorie, crop, period, region
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p5 <- ggplot(data = ghana, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Ghana")+
  theme(plot.title = element_text(hjust = 0.5))
 
p5

Mali Calorie Consumption

mali <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/mali.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(mali)
attach(mali)
## The following objects are masked from ghana:
## 
##     calorie, crop, period, region
## The following objects are masked from ethiopia:
## 
##     calorie, crop, period, region
## The following objects are masked from tanzania:
## 
##     calorie, crop, period, region
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p6 <- ggplot(data = mali, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Mali")+
  theme(plot.title = element_text(hjust = 0.5))
 
p6

Nigeria Calorie Consumption

nigeria <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/nigeria.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(nigeria)
attach(nigeria)
## The following objects are masked from mali:
## 
##     calorie, crop, period, region
## The following objects are masked from ghana:
## 
##     calorie, crop, period, region
## The following objects are masked from ethiopia:
## 
##     calorie, crop, period, region
## The following objects are masked from tanzania:
## 
##     calorie, crop, period, region
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p7 <- ggplot(data = nigeria, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Nigeria")+
  theme(plot.title = element_text(hjust = 0.5))
 
p7

Uganda Calorie Consumption

uganda <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Calorie/uganda.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   crop = col_character(),
##   calorie = col_double()
## )
View(uganda)
attach(uganda)
## The following objects are masked from nigeria:
## 
##     calorie, crop, period, region
## The following objects are masked from mali:
## 
##     calorie, crop, period, region
## The following objects are masked from ghana:
## 
##     calorie, crop, period, region
## The following objects are masked from ethiopia:
## 
##     calorie, crop, period, region
## The following objects are masked from tanzania:
## 
##     calorie, crop, period, region
## The following objects are masked from burkina:
## 
##     calorie, crop, period, region
## The following objects are masked from yield:
## 
##     crop, period, region
## The following objects are masked from production:
## 
##     crop, period, region
################

p8 <- ggplot(data = uganda, aes(x = period, y = calorie)) +
  geom_col(aes(fill = crop), width = 0.5)+
  theme_bw()+
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=8))+
  theme(axis.text.y = element_text(face="bold", color="black", 
                           size=8))+

  ylab("Calorie Consumption (Kg/Capita/Yr)")+
  xlab("")+
scale_fill_manual(values = c("black", "#E69F00", "#56B4E9", "#009E73", "#00AFBB", "#0072B2", "#D55E00", "#800020","green"))+
  theme(legend.position="bottom",legend.justification="left")+coord_flip()+
  ggtitle("Uganda")+
  theme(plot.title = element_text(hjust = 0.5))
 
p8

Imports and Exports Plots

Imports

import_export <- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/Dr Paswel/Leonard/Exports and Imports/import_export.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   region = col_character(),
##   period = col_character(),
##   country = col_character(),
##   export = col_double(),
##   import = col_double(),
##   crop = col_character(),
##   units = col_character()
## )
View(import_export)
attach(import_export)
## The following objects are masked from uganda:
## 
##     crop, period, region
## The following objects are masked from nigeria:
## 
##     crop, period, region
## The following objects are masked from mali:
## 
##     crop, period, region
## The following objects are masked from ghana:
## 
##     crop, period, region
## The following objects are masked from ethiopia:
## 
##     crop, period, region
## The following objects are masked from tanzania:
## 
##     crop, period, region
## The following objects are masked from burkina:
## 
##     crop, period, region
## The following objects are masked from yield:
## 
##     country, crop, period, region
## The following objects are masked from production:
## 
##     country, crop, period, region
east<-subset(import_export, region=="Eastern Africa")
#####################

################# Eastern  Africa

ea1<-ggplot(east, aes(x=period, y=export, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Export (000 tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))
ea1
## Warning: Removed 12 rows containing missing values (`geom_line()`).
## Warning: Removed 25 rows containing missing values (`geom_point()`).

####################
west_1<-subset(import_export, region=="West Africa")
#####################
################# West Africa

wt_1<-ggplot(west_1, aes(x=period, y=export, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Export (000 tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))
wt_1
## Warning: Removed 7 rows containing missing values (`geom_line()`).
## Warning: Removed 27 rows containing missing values (`geom_point()`).

Imports

east_imp<-subset(import_export, region=="Eastern Africa")
#####################

################# Eastern  Africa

m1<-ggplot(east_imp, aes(x=period, y=import, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Import (000 tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("Eastern Africa")+
  theme(plot.title = element_text(hjust = 0.5))
m1
## Warning: Removed 12 rows containing missing values (`geom_line()`).
## Warning: Removed 18 rows containing missing values (`geom_point()`).

west_imp<-subset(import_export, region=="West Africa")
#####################

################# Eastern  Africa

m2<-ggplot(west_imp, aes(x=period, y=import, group=country,shape=country)) +
  geom_line(aes(color=country))+
  geom_point(aes(color=country))+
  ylab("Import (000 tonnes)")+
  xlab("")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,hjust=1,face="bold",color="black",size=7),
          axis.text.y=element_text(face="bold",color="black",size=8)) +
  facet_wrap(~crop)+
  ggtitle("West Africa")+
  theme(plot.title = element_text(hjust = 0.5))
m2
## Warning: Removed 7 rows containing missing values (`geom_point()`).

Additional Species

## mean function
wtp_mean<-function(production,upper_limit=max(
  production)*1.5){
  return(
    data.frame(
      y=4,
      label=paste(
        'Mean=',round(mean(production),0),'\n',
        'Median=',round(median(production),0),'\n',
        'n=',length(production),'\n')
      )
    )
}


# Density plots with semi-transparent fill
zbx<-ggplot(ea, aes(x=log(production), fill=crop)) + geom_density(alpha=.5)+
  facet_wrap(~country,ncol=4)+
    geom_vline(data=ea, aes(xintercept=mean(log(production)),  colour=crop),
               linetype="dashed", size=0.5)+
  
  theme(axis.text.x = element_text(face="bold", color="black", 
                           size=9),
          axis.text.y = element_text(face="bold", color="black", 
                           size=9))+
  theme_bw()+
  xlab("Log (Production(Million tonnes))")+
  ylab("Density")+
       theme(legend.position = c(.9, .8))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.

## Warning: Please use `linewidth` instead.
zbx

### Boxplot

ggplot(ea, aes(x = crop, y = log(production))) + 
  geom_boxplot(data=ea, aes(color=crop, fill=crop), outlier.colour="black", outlier.shape=16, outlier.size=2, color="black")+
  facet_wrap(~country, ncol=4)+
  theme_bw()+
  xlab("")+
  stat_summary(fun.y=mean,geom="point",shape=9,size=2,color="blue")+
  ylab("Log (Production(Million tonnes))")+
  theme(legend.position="")+
  
  theme(axis.text.x = element_text(angle=45,hjust=1, face="bold", color="black", 
                           size=8),
          axis.text.y = element_text(face="bold", color="black", 
                           size=9))+
  stat_summary(
    fun.data=wtp_mean,
    geom="text",
    hjust=0.5,
    vjust=0.9,
    size=1.5,
    color="black")
## Warning: The `fun.y` argument of `stat_summary()` is deprecated as of ggplot2 3.3.0.

## Warning: Please use the `fun` argument instead.

https://onezero.blog/combining-multiple-ggplot2-plots-for-scientific-publications/

Put the plot on the the area by row and column position.

Intergrating the plots , other option instead on patchwork package.

print(plot1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) print(plot2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2)) print(plot3, vp = viewport(layout.pos.row = 2, layout.pos.col = 1)) print(plot4, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))