library(readr)
gap<- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/ACASA/Consolidated/analysis/know_gap.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## country = col_character(),
## district = col_character(),
## mt = col_double(),
## mulch = col_double(),
## rot = col_double(),
## intcrp = col_double()
## )
attach(gap)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.4 v dplyr 1.0.7
## v tibble 3.1.2 v stringr 1.4.0
## v tidyr 1.1.3 v forcats 0.5.1
## v purrr 0.3.4
## Warning: package 'forcats' was built under R version 4.1.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(plotrix)
library(epiDisplay)
## Loading required package: foreign
## Loading required package: survival
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: nnet
##
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:ggplot2':
##
## alpha
library(ggplot2)
library(ggpubr)
library(dplyr)
library(agricolae)
library(lmerTest)
## Loading required package: lme4
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
library(emmeans) # we use this package to have the means of particlar factors
## Warning: package 'emmeans' was built under R version 4.1.1
library(multcompView) #for the cld function for mean grouping
library(multcomp)
## Loading required package: mvtnorm
## Loading required package: TH.data
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
library(MASS)
library(patchwork)
## Warning: package 'patchwork' was built under R version 4.1.1
##
## Attaching package: 'patchwork'
## The following object is masked from 'package:MASS':
##
## area
country=as.factor(country)
Knowledge Gap
ca_overall<- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/ACASA/Consolidated/analysis/gap_overall.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## country = col_character(),
## ca_system = col_character(),
## gap = col_double()
## )
attach(ca_overall)
## The following objects are masked _by_ .GlobalEnv:
##
## country, gap
## The following object is masked from gap:
##
## country
country=as.factor(country)
ca_system=as.factor(ca_system)
p = ggplot(data=ca_overall,
aes(x = reorder(ca_system,gap),y = gap, ymin=min(gap), ymax = max (gap)))+ geom_pointrange(aes(col=ca_system))+
xlab('')+ ylab("Overall Knowledge Gap (Know- Not-used)")+
geom_errorbar(aes(ymin=min(gap), ymax=max (gap),col=ca_system),width=0.5,cex=1)+
facet_wrap(~country,strip.position="top",nrow=1,scales = "free_y")+
theme(plot.title=element_text(size=10,face="bold"),
axis.text.x=element_text(face="bold"),
axis.text.y=element_text(size=10,color="black"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))+ coord_flip()+theme(legend.position = "")
p

ggsave("know-do-gap-overall.pdf", p, width=12, height=4)
Lattice-like forest plots
MT
pmt = ggplot(data=gap,
aes(x = reorder(district,mt),y = mt, ymin=min(mt), ymax = max (mt)))+ geom_pointrange(aes(col=country))+
xlab('Minimum Tillage')+ ylab("")+
geom_errorbar(aes(ymin=min(mt), ymax=max (mt),col=country),width=0.5,cex=1)+
facet_wrap(~country,strip.position="top",nrow=1,scales = "free_y")+theme_bw()+
theme(plot.title=element_text(size=8,face="bold"),
axis.text.x=element_text(size=8,face="bold",color="black"),
axis.text.y=element_text(size=9,color="black"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))+ coord_flip()+theme(legend.position = "")
pmt

Rotation
prot = ggplot(data=gap,
aes(x = reorder(district,rot),y = rot, ymin=min(rot), ymax = max (rot)))+ geom_pointrange(aes(col=country))+
xlab('Rotation')+ ylab("")+
geom_errorbar(aes(ymin=min(rot), ymax=max (rot),col=country),width=0.5,cex=1)+
facet_wrap(~country,strip.position="top",nrow=1,scales = "free_y")+theme_bw()+
theme(plot.title=element_text(size=8,face="bold"),
axis.text.x=element_text(size=8,face="bold",color="black"),
axis.text.y=element_text(size=8,color="black"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))+ coord_flip()+theme(legend.position = "")
prot

Mulching
pmch = ggplot(data=gap,
aes(x = reorder(district,mulch),y = mulch, ymin=min(mulch), ymax = max (mulch)))+ geom_pointrange(aes(col=country))+
xlab('Mulching')+ ylab("")+
geom_errorbar(aes(ymin=min(mulch), ymax=max (mulch),col=country),width=0.5,cex=1)+
facet_wrap(~country,strip.position="top",nrow=1,scales = "free_y")+theme_bw()+
theme(plot.title=element_text(size=8,face="bold"),
axis.text.x=element_text(size=8,face="bold",color="black"),
axis.text.y=element_text(size=8,color="black"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))+ coord_flip()+theme(legend.position = "")
pmch

Intercropping
pint = ggplot(data=gap,
aes(x = reorder(district,intcrp),y = intcrp, ymin=min(intcrp), ymax = max (intcrp)))+ geom_pointrange(aes(col=country))+
xlab('Intercrop')+ ylab("Knowledge Gap (Know- Not-used)")+
geom_errorbar(aes(ymin=min(intcrp), ymax=max (intcrp),col=country),width=0.5,cex=1)+
facet_wrap(~country,strip.position="top",nrow=1,scales = "free_y")+theme_bw()+
theme(plot.title=element_text(size=8,face="bold"),
axis.text.x=element_text(size=8,face="bold",color="black"),
axis.text.y=element_text(size=8,color="black"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))+ coord_flip()+theme(legend.position = "")
pint

png(filename="ca_systems.png", width=1000, height=600)
all= pmt/prot/pmch/pint
ggsave("ca_systemes_know_dogap.pdf", all, width=11, height=8.5)
Knowledge gap by cropping systems
ca_gap<- read_csv("C:/Users/LCHIPINDU/OneDrive - CIMMYT/CIMMYT/ACASA/Consolidated/analysis/ca_know_gap.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## country = col_character(),
## district = col_character(),
## ca_system = col_character(),
## know_gap = col_double()
## )
attach(ca_gap)
## The following objects are masked _by_ .GlobalEnv:
##
## ca_system, country
## The following objects are masked from ca_overall:
##
## ca_system, country
## The following objects are masked from gap:
##
## country, district
country=as.factor(country)
district=as.factor(district)
ca_system=as.factor(ca_system)
p = ggplot(data=ca_gap,
aes(x = reorder(district,know_gap),y =know_gap, ymin=know_gap, ymax = know_gap))+ geom_pointrange(aes(col=country))+
geom_hline(aes(fill=district),yintercept =50, linetype=2)+
xlab('')+ ylab("Knowledge Gap (Know- Not-used)")+
geom_errorbar(aes(ymin=min(know_gap), ymax=max (know_gap),col=country),width=0.5,cex=1)+
facet_wrap(~country,strip.position="left",nrow=3,scales = "free_y")+
theme(plot.title=element_text(size=8,face="bold"),
axis.text.x=element_text(size=8,face="bold",color="black"),
axis.text.y=element_text(size=7.2,color="black"),
axis.title=element_text(size=9,face="bold"),
strip.text.y = element_text(hjust=0,vjust = 0,face="bold"))
## Warning: geom_hline(): Ignoring `mapping` because `yintercept` was provided.
p+ coord_flip()+facet_wrap(~ca_system)

ggplot(data =ca_gap,
aes(x = ca_system,
y = know_gap,
fill = ca_system,
colour =ca_system)) +
geom_violin(alpha = 1,
position = position_nudge(x = .2, y = 0)) +
stat_ydensity(geom = "bar", colour = "white", fill = "white", width = .8,
position = position_nudge(x = -.05, y = 0)) +
geom_jitter( width = .15,
size = .5,
alpha = 0.5) +
geom_boxplot(width = 0.4,
outlier.shape = NA,
alpha = 0.8,
color = "black",
notch=FALSE) +
theme_bw() +
theme(legend.position = "none") +
scale_color_brewer(palette = "Spectral") +
scale_fill_brewer(palette = "Spectral") +facet_wrap(~country)+
theme(axis.text.x = element_text(size=8))+
ylab("Knowledge Gap (Know- Not-used)")+
xlab("")

ggplot(data =ca_gap,
aes(x = country,
y = know_gap,
fill = ca_system,
colour =ca_system))+
geom_jitter( width = .15,
size = .5,
alpha = 0.5) +
geom_boxplot(width = 0.4,
outlier.shape = NA,
alpha = 0.8,
color = "black",
notch=FALSE) +
theme_bw() +
scale_color_brewer(palette = "Spectral") +
scale_fill_brewer(palette = "Spectral") +
theme(axis.text.x = element_text(size=8))+theme(legend.position = c(.65, .85))+
ylab("Knowledge Gap (Know- Not-used)")+
xlab("")
