R/islandbarplot.R

#' Function for creating a series of barcharts (one per island) showing local alpha diversity for each plot
#' 
#' @ indf = name of input dataframe alpha diversity scores          
#' 

islandbarplot<-function(indf,save){
    isl.l<-unique(alpha.plot$Island)
    for (i in 1:length(isl.l)){
        # subset island
        tmp<-subset(alpha.plot,Island==isl.l[i])
        # create plots
        tmp.plot<-ggplot(data=tmp,aes(x=Coloniz.,y=Alpha))+geom_bar(stat="identity",fill="#00BA38",
        colour="black",size=0.5)+theme_bw()+geom_text(aes(label=Alpha),vjust=0.7,hjust=0,size=5)+
        ylab("Alpha diversity")+xlab("Species status")+theme(text = element_text(size=20,colour="black"),
        axis.text=element_text(colour="black"),strip.text=element_text(size=15, face="bold"))+
        facet_wrap(~Plot,scales="free_x")+ggtitle(isl.l[i])+theme(plot.title = element_text(hjust = 0.5))
        
        # create filename
        filen<-paste(save,"/",isl.l[i],".png",sep="")
        ggsave(plot=tmp.plot,file=filen,width=9.5,height=9,dpi=400)
    }
}
drmarcogir/Rmacdiv documentation built on May 15, 2019, 12:58 p.m.