### Script designed by Yann Gager for morphometry of Molossus ### http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0150780 ### Download packages require(ggplot2) require(gridExtra) require(MASS) ## Download your dataset (here called "combin") ## Replace the variables in the graph ("mass_of_bat","FA","species") ## Replace colors coded manually(scale_colour_manual & scale_fill_manual) #scatterplot of x and y variables ### Placeholder plot - prints nothing at all empty <- ggplot() + geom_point(aes(1,1), colour="white") + theme(plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(),axis.line = element_line(colour = "white")) scatter3sp <- ggplot(combin,aes(mass_of_bat, FA)) + geom_point(aes(colour=species)) + scale_colour_manual(values = c("#00FF99","blue","orange"),name="Species",labels=c("M. bondae","M. coibensis","M. molossus")) + theme(legend.position=c(1,1),legend.direction="horizontal",legend.justification=c(1,1),axis.title.x = element_text(face="bold"),axis.title.y = element_text(face="bold"),axis.line = element_line(colour = "black"),panel.background = element_rect(fill="white"),legend.background = element_rect(fill="white"),legend.key = element_rect(fill="white"),legend.text = element_text(face="italic")) + xlab("Mass (g)") + ylab("Forearm length (mm)") #+ scale_shape_discrete(name="Sex") #Green for currentium: "#009E73" / scatter3sp #marginal density of x - plot on top plot_top3sp <- ggplot(combin, aes(mass_of_bat, fill=species)) + geom_density(alpha=.5) + scale_fill_manual(values = c("#00FF99", "blue", "orange")) + theme(legend.position = "none",panel.background = element_rect(fill="white"),axis.line = element_line(colour = "black")) + xlab("") + ylab("") #marginal density of y - plot on the right plot_right3sp <- ggplot(combin, aes(FA, fill=species)) + geom_density(alpha=.5) + coord_flip() + scale_fill_manual(values = c("#00FF99","blue","orange")) + theme(legend.position = "none",panel.background = element_rect(fill="white"),axis.line = element_line(colour = "black")) + xlab("") + ylab("") #arrange the plots together, with appropriate height and width for each row and column pdf("C:/Users/ygager/Desktop/PHD/WRITING/2-Diversity/FIGURES/Morpho-2K+cur.pdf",width=14,height=8) combiplot3sp <- grid.arrange(plot_top3sp, empty, scatter3sp, plot_right3sp, ncol=2, nrow=2, widths=c(4, 1), heights=c(1.5, 4)) dev.off()