library(readr)
legume <- read_csv("~/Cropping Systems/legume.csv")
## Parsed with column specification:
## cols(
## country = col_character(),
## agroecoregion = col_character(),
## cropping_system = col_character(),
## legume_cultivar = col_character(),
## maize_grain = col_double()
## )
View(legume)
attach(legume)
Loading the required packages
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)
country=as.factor(country)
agroecoregion=as.factor(agroecoregion)
cropping_system=c(cropping_system)
cropping_systems=factor(cropping_system,levels = c("Conv_sole","Conv_intercrop","CA_intercrop","CA_rotation"),ordered = TRUE)
Legume Cultivar
## setting outiliers to zero
theme_set(theme_gray(base_size =8)) ###This sets the font sizes of anything writt
ggplot(legume, aes(x = legume_cultivar, y = maize_grain))+geom_violin()+geom_boxplot(size=0.2,outlier.colour = "red",outlier.shape = 1, shape=6) + geom_smooth(method=lm)+ ylab("Maize Grain yield [kg/ha]") + xlab("Legume Cultivar")
theme_set(theme_gray(base_size =8))
m <- ggplot(data=legume,aes(x=legume_cultivar, y=maize_grain))
m + geom_violin(size=0.9,shape=8) + geom_boxplot(width=.2, outlier.size=0,fill=c("grey","grey","grey","grey","grey","grey","grey","grey"))+ylab("Maize Grain yield [kg/ha]") + xlab("Legume Cultivar")
## Warning: Ignoring unknown parameters: shape
h<-ggplot(legume, aes(legume_cultivar, maize_grain, shape=cropping_systems, color=cropping_systems )) + geom_boxplot(data =legume, size=0.5, aes(color=cropping_systems, shape=cropping_systems,notch=TRUE), position = "jitter")+
geom_smooth(method="lm", level = 0.65,position = "jitter")+
ylab("Maize grain yield [kg/ha]") + xlab("Legume Cultivar")+
theme(legend.position = c(0.90, 0.82))+coord_flip()
## Warning: Ignoring unknown aesthetics: notch
h
## Warning: Using shapes for an ordinal variable is not advised
theme_set(theme_gray(base_size =7)) ###This sets the font sizes of anything writt
ggplot(legume, aes(x = legume_cultivar, y = maize_grain))+geom_boxplot(size=1,outlier.colour = "red",outlier.shape = 1, shape=6) + geom_smooth(method=lm)+ ylab("Maize Grain yield [kg/ha]") + xlab("Legume Cultivar")
theme_set(theme_gray(base_size =5)) ###This sets the font sizes of anything writt
ggplot(legume, aes(x=cropping_system, y = maize_grain))+geom_boxplot(size=1,outlier.colour = "red",outlier.shape = 1, shape=6) + geom_smooth(method=lm)+ ylab("Maize Grain yield [kg/ha]") + xlab("Cropping Systems")+facet_wrap(legume_cultivar ~ agroecoregion)
theme_set(theme_gray(base_size =9)) ###This sets the font sizes of anything writt
ggplot(legume, aes(x = country , y = maize_grain))+geom_boxplot(size=1,outlier.colour = "red",outlier.shape = 1, shape=6) + geom_smooth(method=lm)+ ylab("Maize Grain yield [kg/ha]") + xlab("Country")+facet_wrap(legume_cultivar~.)