library(readr)
rsd <- read_csv("~/Dr Nyagumbo/Final data set/rsd.csv")
## Parsed with column specification:
## cols(
## country = col_character(),
## agroecoregion = col_character(),
## treatment = col_character(),
## association = col_character(),
## season = col_character(),
## season_since = col_double(),
## season_class = col_character(),
## rainfall = col_double(),
## rainfall_class = col_character(),
## Refined_texture = col_character(),
## drainage_class = col_logical(),
## drainage_scale = col_logical(),
## maize_grain = col_double(),
## RSD = col_character()
## )
## Warning: 4018 parsing failures.
## row col expected actual file
## 1548 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/rsd.csv'
## 1548 drainage_scale 1/0/T/F/TRUE/FALSE 5 '~/Dr Nyagumbo/Final data set/rsd.csv'
## 1549 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/rsd.csv'
## 1549 drainage_scale 1/0/T/F/TRUE/FALSE 5 '~/Dr Nyagumbo/Final data set/rsd.csv'
## 1550 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/rsd.csv'
## .... .............. .................. ....................... ......................................
## See problems(...) for more details.
View(rsd)
attach(rsd)
library(ggplot2)
library(maps)
library(ggalt)
library(extrafontdb)
library(MASS)
library(pscl)
## Classes and Methods for R developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University
## Simon Jackman
## hurdle and zeroinfl functions by Achim Zeileis
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(gridExtra)
library(repr) ### adjusting the length and width of your plot
library(beanplot)
library("devtools")
library("yarrr")
## Loading required package: jpeg
## Loading required package: BayesFactor
## Loading required package: coda
## Loading required package: Matrix
## ************
## Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
##
## Type BFManual() to open the manual.
## ************
## Loading required package: circlize
## ========================================
## circlize version 0.4.6
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: http://jokergoo.github.io/circlize_book/book/
##
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
## in R. Bioinformatics 2014.
## ========================================
## yarrr v0.1.5. Citation info at citation('yarrr'). Package guide at yarrr.guide()
## Email me at Nathaniel.D.Phillips.is@gmail.com
##
## Attaching package: 'yarrr'
## The following object is masked from 'package:ggplot2':
##
## diamonds
library(agricolae)
library(easynls)
library(MVN)
## sROC 0.1-2 loaded
library(lme4)
library(ggsignif)
library(ggpubr)
## Loading required package: magrittr
library(tidyverse)
## -- Attaching packages ---------------------- tidyverse 1.2.1 --
## v tibble 2.1.1 v dplyr 0.8.0.1
## v tidyr 0.8.3 v stringr 1.4.0
## v purrr 0.3.2 v forcats 0.4.0
## -- Conflicts ------------------------- tidyverse_conflicts() --
## x psych::%+%() masks ggplot2::%+%()
## x psych::alpha() masks ggplot2::alpha()
## x dplyr::combine() masks gridExtra::combine()
## x tidyr::expand() masks Matrix::expand()
## x tidyr::extract() masks magrittr::extract()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x purrr::map() masks maps::map()
## x dplyr::select() masks MASS::select()
## x purrr::set_names() masks magrittr::set_names()
country=as.factor(country)
#site=as.factor(site)
agroecoregion=as.factor(agroecoregion)
#system=as.factor(system)
#systems=factor(system,levels = c("Conv","CA",order=TRUE))
#legume_cultivar=as.factor(legume_cultivar)
#cropping_systems=factor(cropping_system,levels = c("Conv","CA_sole","CA_intercrop","CA_rotation"),ordered = TRUE)
season_class=as.factor(season_class)
season_clas=factor(season_class,levels = c("(0-2)","(3-5)","(>5)"),ordered = TRUE)
rainfall_class=as.factor(rainfall_class)
rainfall_clas=factor(rainfall_class,levels = c("(<700)","(700-1300)","(>1300)"),ordered = TRUE)
#textureclass=as.factor(textureclass)
drainage_class=c(drainage_class)
#drainage_clas=factor(drainage_class,levels = c("Well drained",
#"Moderately well drained","Somewhat poorly drained","Poorly drained"),ordered=TRUE)
RSD=as.factor(RSD)
Refined_texture=as.factor(Refined_texture)
##################################################################
rsd1<-aov(maize_grain~RSD+season_class+rainfall_class+
agroecoregion+Refined_texture,data = rsd)
anova(rsd1)
## Analysis of Variance Table
##
## Response: maize_grain
## Df Sum Sq Mean Sq F value Pr(>F)
## RSD 2 359431265 179715633 61.9085 < 2.2e-16 ***
## season_class 2 41506885 20753443 7.1492 0.0007993 ***
## rainfall_class 2 16776359 8388180 2.8896 0.0557585 .
## agroecoregion 1 506261752 506261752 174.3971 < 2.2e-16 ***
## Refined_texture 2 37230483 18615242 6.4126 0.0016638 **
## Residuals 2939 8531695036 2902924
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(rsd1)
## Df Sum Sq Mean Sq F value Pr(>F)
## RSD 2 3.594e+08 179715633 61.908 < 2e-16 ***
## season_class 2 4.151e+07 20753443 7.149 0.000799 ***
## rainfall_class 2 1.678e+07 8388180 2.890 0.055759 .
## agroecoregion 1 5.063e+08 506261752 174.397 < 2e-16 ***
## Refined_texture 2 3.723e+07 18615242 6.413 0.001664 **
## Residuals 2939 8.532e+09 2902924
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 615 observations deleted due to missingness
####################### graph1
## sample size and mean function
stat_box_data <- function(maize_grain, upper_limit = max(maize_grain)*1.5) {
return(
data.frame(
y = 11500,
label = paste('N =', length(maize_grain), '\n',
'Mean =', round(mean(maize_grain), 0), '\n')
)
)
}
m<-ggplot(rsd, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.8,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6,fill=c("grey","grey","grey")) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=3
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=10),
axis.text.y = element_text(face="bold", color="black",
size=10))+geom_text(data =rsd, x = 1, y = 3000, label = "b")+geom_text(data =rsd, x = 2, y = 3800, label = "a")+geom_text(data =rsd, x = 3, y = 3800, label = "a")+
ylim(100,11500)
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 282 rows containing non-finite values (stat_boxplot).
## Warning: Removed 282 rows containing non-finite values (stat_smooth).
## Warning: Removed 282 rows containing non-finite values (stat_summary).
## Warning: Removed 282 rows containing non-finite values (stat_summary).

m<-ggplot(rsd, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.6,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6,fill=c("grey","grey","grey","grey","grey","grey")) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+facet_wrap(.~agroecoregion)+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=2.5
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=7),
axis.text.y = element_text(face="bold", color="black",
size=9))+geom_text(data =rsd, x = 1, y = 3000, label = "b")+geom_text(data =rsd, x = 2, y = 3100, label = "a")+geom_text(data =rsd, x = 3, y = 2600, label = "a")+
ylim(100,11500)+theme(legend.position = c(0.85, 0.85))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 282 rows containing non-finite values (stat_boxplot).
## Warning: Removed 282 rows containing non-finite values (stat_smooth).
## Warning: Removed 282 rows containing non-finite values (stat_summary).
## Warning: Removed 282 rows containing non-finite values (stat_summary).

m<-ggplot(rsd, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.6,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6,fill=c("grey","grey","grey","grey","grey","grey","grey","grey","grey")) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+facet_wrap(.~rainfall_class)+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=2.5
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=5),
axis.text.y = element_text(face="bold", color="black",
size=9))+geom_text(data =rsd, x = 1, y = 2500, label = "a")+geom_text(data =rsd, x = 2, y = 2700, label = "b")+geom_text(data =rsd, x = 3, y = 2700, label = "b")+
ylim(100,11500)+theme(legend.position = c(0.85, 0.85))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 282 rows containing non-finite values (stat_boxplot).
## Warning: Removed 282 rows containing non-finite values (stat_smooth).
## Warning: Removed 282 rows containing non-finite values (stat_summary).
## Warning: Removed 282 rows containing non-finite values (stat_summary).

m<-ggplot(rsd, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.6,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6,fill=c("grey","grey","grey","grey","grey","grey","grey","grey","grey")) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+facet_wrap(.~season_class)+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=2.5
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=5),
axis.text.y = element_text(face="bold", color="black",
size=9))+geom_text(data =rsd, x = 1, y = 3500, label = "a")+geom_text(data =rsd, x = 2, y = 3200, label = "b")+geom_text(data =rsd, x = 3, y = 4000, label = "a")+
ylim(100,11500)+theme(legend.position = c(0.85, 0.85))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 282 rows containing non-finite values (stat_boxplot).
## Warning: Removed 282 rows containing non-finite values (stat_smooth).
## Warning: Removed 282 rows containing non-finite values (stat_summary).
## Warning: Removed 282 rows containing non-finite values (stat_summary).

#####################################
library(readr)
text <- read_csv("~/Dr Nyagumbo/Final data set/text.csv")
## Parsed with column specification:
## cols(
## country = col_character(),
## agroecoregion = col_character(),
## treatment = col_character(),
## association = col_character(),
## season = col_character(),
## season_since = col_double(),
## season_class = col_character(),
## rainfall = col_double(),
## rainfall_class = col_character(),
## Refined_texture = col_character(),
## drainage_class = col_logical(),
## drainage_scale = col_logical(),
## maize_grain = col_double(),
## RSD = col_character()
## )
## Warning: 3988 parsing failures.
## row col expected actual file
## 1121 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/text.csv'
## 1121 drainage_scale 1/0/T/F/TRUE/FALSE 5 '~/Dr Nyagumbo/Final data set/text.csv'
## 1122 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/text.csv'
## 1122 drainage_scale 1/0/T/F/TRUE/FALSE 5 '~/Dr Nyagumbo/Final data set/text.csv'
## 1123 drainage_class 1/0/T/F/TRUE/FALSE Somewhat poorly drained '~/Dr Nyagumbo/Final data set/text.csv'
## .... .............. .................. ....................... .......................................
## See problems(...) for more details.
View(text)
attach(text)
## The following objects are masked _by_ .GlobalEnv:
##
## agroecoregion, country, drainage_class, rainfall_class,
## Refined_texture, RSD, season_class
## The following objects are masked from rsd:
##
## agroecoregion, association, country, drainage_class,
## drainage_scale, maize_grain, rainfall, rainfall_class,
## Refined_texture, RSD, season, season_class, season_since,
## treatment
#################################################################
country=as.factor(country)
#site=as.factor(site)
agroecoregion=as.factor(agroecoregion)
#system=as.factor(system)
#systems=factor(system,levels = c("Conv","CA",order=TRUE))
#legume_cultivar=as.factor(legume_cultivar)
#cropping_systems=factor(cropping_system,levels = c("Conv","CA_sole","CA_intercrop","CA_rotation"),ordered = TRUE)
season_class=as.factor(season_class)
season_clas=factor(season_class,levels = c("(0-2)","(3-5)","(>5)"),ordered = TRUE)
rainfall_class=as.factor(rainfall_class)
rainfall_clas=factor(rainfall_class,levels = c("(<700)","(700-1300)","(>1300)"),ordered = TRUE)
#textureclass=as.factor(textureclass)
drainage_class=c(drainage_class)
#drainage_clas=factor(drainage_class,levels = c("Well drained",
#"Moderately well drained","Somewhat poorly drained","Poorly drained"),ordered=TRUE)
RSD=as.factor(RSD)
Refined_texture=as.factor(Refined_texture)
####################################################################
stat_box_data <- function(maize_grain, upper_limit = max(maize_grain)*1.5) {
return(
data.frame(
y = 11500,
label = paste('N =', length(maize_grain), '\n',
'Mean =', round(mean(maize_grain), 0), '\n')
)
)
}
###############################################################
m<-ggplot(text, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.6,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6,fill=c("grey","grey","grey","grey","grey","grey","grey","grey","grey")) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+facet_wrap(.~Refined_texture)+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=2
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=5),
axis.text.y = element_text(face="bold", color="black",
size=9))+geom_text(data =text, x = 1, y = 2700, label = "a")+geom_text(data =text, x = 2, y = 3500, label = "b")+geom_text(data =text, x = 3, y = 3800, label = "a")+
ylim(100,11500)+theme(legend.position = c(0.85, 0.85))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 166 rows containing non-finite values (stat_boxplot).
## Warning: Removed 166 rows containing non-finite values (stat_smooth).
## Warning: Removed 166 rows containing non-finite values (stat_summary).
## Warning: Removed 166 rows containing non-finite values (stat_summary).

########################################
library(readr)
dr <- read_csv("~/Dr Nyagumbo/Final data set/dr.csv")
## Parsed with column specification:
## cols(
## country = col_character(),
## agroecoregion = col_character(),
## treatment = col_character(),
## association = col_character(),
## season = col_character(),
## season_since = col_double(),
## season_class = col_character(),
## rainfall = col_double(),
## rainfall_class = col_character(),
## Refined_texture = col_character(),
## drainage_class = col_character(),
## drainage_scale = col_double(),
## maize_grain = col_double(),
## RSD = col_character()
## )
View(dr)
attach(dr)
## The following objects are masked _by_ .GlobalEnv:
##
## agroecoregion, country, drainage_class, rainfall_class,
## Refined_texture, RSD, season_class
## The following objects are masked from text:
##
## agroecoregion, association, country, drainage_class,
## drainage_scale, maize_grain, rainfall, rainfall_class,
## Refined_texture, RSD, season, season_class, season_since,
## treatment
## The following objects are masked from rsd:
##
## agroecoregion, association, country, drainage_class,
## drainage_scale, maize_grain, rainfall, rainfall_class,
## Refined_texture, RSD, season, season_class, season_since,
## treatment
#################################################################
country=as.factor(country)
#site=as.factor(site)
agroecoregion=as.factor(agroecoregion)
#system=as.factor(system)
#systems=factor(system,levels = c("Conv","CA",order=TRUE))
#legume_cultivar=as.factor(legume_cultivar)
#cropping_systems=factor(cropping_system,levels = c("Conv","CA_sole","CA_intercrop","CA_rotation"),ordered = TRUE)
season_class=as.factor(season_class)
season_clas=factor(season_class,levels = c("(0-2)","(3-5)","(>5)"),ordered = TRUE)
rainfall_class=as.factor(rainfall_class)
rainfall_clas=factor(rainfall_class,levels = c("(<700)","(700-1300)","(>1300)"),ordered = TRUE)
#textureclass=as.factor(textureclass)
drainage_class=c(drainage_class)
drainage_clas=factor(drainage_class,levels = c("Well drained",
"Moderately well drained","Somewhat poorly drained","Poorly drained"),ordered=TRUE)
RSD=as.factor(RSD)
Refined_texture=as.factor(Refined_texture)
####################################################################
m<-ggplot(dr, aes(x = RSD, y = maize_grain))+ geom_boxplot(size=0.5,varwidth =FALSE,outlier.colour = "red",outlier.shape = 2, shape=6) + geom_smooth(method=lm)+ ylab("Maize Grain Yield [kg/ha]") + xlab("Reduced Soil Disturbance")+facet_wrap(.~drainage_class)+
stat_summary(fun.y=mean, geom="point", shape=10, size=2, color="blue", fill="red")+
stat_summary(
fun.data = stat_box_data,
geom = "text",
hjust = 0.5,
vjust = 0.9,
size=2
)+ theme_classic(base_size = 14)+ ylim(100, 11500)+ theme(axis.text.x = element_text(face="bold", color="black",
size=5),
axis.text.y = element_text(face="bold", color="black",
size=9))+
ylim(100,11500)+theme(legend.position = c(0.85, 0.85))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
m
## Warning: Removed 17 rows containing non-finite values (stat_boxplot).
## Warning: Removed 17 rows containing non-finite values (stat_smooth).
## Warning: Removed 17 rows containing non-finite values (stat_summary).
## Warning: Removed 17 rows containing non-finite values (stat_summary).
