Skip to content

Instantly share code, notes, and snippets.

@MartinMacharia
Last active September 20, 2017 17:40
Show Gist options
  • Save MartinMacharia/39bbc0bb8401540aefd0ae24dab32f75 to your computer and use it in GitHub Desktop.
Save MartinMacharia/39bbc0bb8401540aefd0ae24dab32f75 to your computer and use it in GitHub Desktop.
ggplot2
#Box plot
#Colour
setwd("c:/Users/machariam/Desktop/Rwanda PW Impact report/Logit")
list.files()
Dat.Yield=read.csv("Dat.Yield.csv")
library(ggplot2)
ggplot(Dat.Yield, aes(x = aez, y = YieldKgHA, fill=Use)) +
geom_boxplot(position=position_dodge(0.8))+
coord_flip()+
stat_summary(fun.y=mean, colour="black", geom="point",shape=18, size=3,position=position_dodge(width=0.9)) +
labs(x = "Agro ecological zones")+
labs(y = "Maize yield (Kg/Ha)")+
scale_fill_discrete(name="Plantclinic Use")+
theme(legend.position = "bottom") + #carries many things including tittle fonts#
guides(fill=guide_legend(reverse=TRUE), colour=guide_legend(reverse=TRUE))+
scale_y_continuous(breaks = seq(0, 4500, 500),limits=c(300, 4500))
#Grey Scale
ggplot(data = Dat.Yield, aes(aez, YieldKgHA, fill = Use)) +
geom_boxplot(position=position_dodge(0.8))+
coord_flip()+
stat_summary(fun.y=mean, colour="black", geom="point",shape=18, size=3,position=position_dodge(width=0.9)) +
labs(x = "Agro ecological zones")+
labs(y = "Maize yield (Kg/Ha)")+
labs(fill="Plant clinic use") +
scale_color_manual(values = c("gray30","darkgrey"),labels = c("Yes","No")) +
scale_fill_manual(values = c("gray40","grey75"),labels = c("Yes","No")) +
theme(legend.position = "bottom") +
guides(fill=guide_legend(reverse=TRUE),
colour=guide_legend(reverse=TRUE))+
scale_y_continuous(breaks = seq(0, 4500, 500),limits=c(300, 4500))
@MartinMacharia
Copy link
Author

rplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment