require(ggplot2) require(ggforce) require(png) require(grid) p1 <- ggplot()+ ggtitle("Top view")+xlab("Length (cm)")+ylab("Width (cm)")+ geom_rect(mapping=aes(xmin=0, xmax=100, ymin=0, ymax=50, fill="Exposure tank"), color="black", alpha=0.5)+ geom_rect(mapping=aes(xmin=27, xmax=42, ymin=8.5, ymax=41.5, fill="Experimental tank"), color="black", alpha=0.5)+ geom_rect(mapping=aes(xmin=42.5, xmax=57.5, ymin=8.5, ymax=41.5, fill="Experimental tank"), color="black", alpha=0.5)+ geom_rect(mapping=aes(xmin=58, xmax=73, ymin=8.5, ymax=41.5, fill="Experimental tank"), color="black", alpha=0.5)+ geom_rect(mapping=aes(xmin=28, xmax=41, ymin=22.5, ymax=40.5, fill="Crab box"), color="black")+ geom_rect(mapping=aes(xmin=43.5, xmax=56.5, ymin=22.5, ymax=40.5, fill="Crab box"), color="black")+ geom_rect(mapping=aes(xmin=59, xmax=72, ymin=22.5, ymax=40.5, fill="Crab box"), color="black")+ scale_fill_manual(breaks = c("Crab box", "Speaker", "Experimental tank", "Exposure tank"), values=c("#7575ff", "#00b8ff", "white", "Lightblue"), name = "Item")+ #scale_color_manual(breaks = c("Wire"), # values=c("#734326"), name = "")+ scale_x_continuous(breaks=seq(0,100,10), limits = c(0,100))+ scale_y_continuous(breaks=seq(0,50,10), limits = c(0,50))+ theme_bw() p1 #ggsave('Set-up_top.png', p1, png(), units = "in", width = 8.3/2, height = 2.77) img <- readPNG("Silhouettes/CrabSilhouette_et.png") p1 <- p1 + annotation_raster(img, xmin = 61.5, xmax = 69.5, ymin = 14, ymax = 22) img <- readPNG("CrabSilhouette_cb.png") p1 <- p1 + annotation_raster(img, xmin = 46, xmax = 54, ymin = 27, ymax = 35) img <- readPNG("Silhouettes/MussleAnatomy_et.png") p1 <- p1 + annotation_raster(img, xmin = 33, xmax = 35, ymin = 10, ymax = 14) p1 <- p1 + annotation_raster(img, xmin = 49, xmax = 51, ymin = 10, ymax = 14) p1 <- p1 + annotation_raster(img, xmin = 64, xmax = 66, ymin = 10, ymax = 14) p2 <- ggplot()+ ggtitle("Side view")+xlab("Width (cm)")+ylab("Height (cm)")+ geom_rect(mapping=aes(xmin=0, xmax=50, ymin=0, ymax=42, fill = "Exposure tank"), color=NA, alpha=0.5)+ geom_rect(mapping=aes(xmin=0, xmax=50, ymin=0, ymax=50), fill = NA, color="black", alpha=0.5)+ # Exposure tank + crab box geom_rect(mapping=aes(xmin=8.5, xmax=41.5, ymin=29, ymax=44, fill="Experimental tank"), color="black", alpha=0.5)+ geom_rect(mapping=aes(xmin=9.5, xmax=27.5, ymin=32.5, ymax=42, fill="Crab box"), color="black")+ # Mussel annotation_raster(img, xmin = 38, xmax = 40, ymin = 30, ymax = 34)+ # Cables geom_path(aes(x = c(38.4,39), y = c(33.0,65), color = "Cable"))+ geom_path(aes(x = c(39.6,39), y = c(33.0,65), color = "Cable"))+ geom_path(aes(x = c(38.0,38.4), y = c(32.5,33.8), color = "Valve gape monitor"), size = 1.2)+ geom_path(aes(x = c(39.6,40.0), y = c(33.8,32.5), color = "Valve gape monitor"), size = 1.2)+ # Speaker geom_rect(mapping=aes(xmin=(42.85-25), xmax=(57.15-25), ymin=2, ymax=6, fill="Speaker"), color="black", alpha=1)+ geom_rect(mapping=aes(xmin=(40.85-25), xmax=(59.15-25), ymin=4.5, ymax=5, fill="Speaker"), color="black", alpha=1)+ geom_rect(mapping=aes(xmin=(42.95-25), xmax=(57.05-25), ymin=2.5, ymax=5.7, fill="Speaker"), color=NA, alpha=1)+ # Speaker mesh geom_line(aes(x = c(17.1,17.1), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(32.9,32.9), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(17.1,32.9), y = c(4,4), color = "Mesh"))+ geom_line(aes(x = c(17.1,18.3), y = c(1.008,0), color = "Mesh"))+ geom_line(aes(x = c(17.3,22.3), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(21.3,26.3), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(25.3,30.3), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(29.3,32.9), y = c(4.2,1.176), color = "Mesh"))+ geom_line(aes(x = c(20.6,17.1), y = c(4.2,1.26), color = "Mesh"))+ geom_line(aes(x = c(24.6,19.6), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(28.6,23.6), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(32.6,27.6), y = c(4.2,0), color = "Mesh"))+ geom_line(aes(x = c(32.9,31.6), y = c(1.092,0), color = "Mesh"))+ geom_line(aes(x = c(.6,49.4), y = c(42,42), color = "Water level"), size = 1, linetype = "dashed")+ #scale_fill_manual(breaks = c("Bottle", "Mussel", "Speaker", "Stick", "Tank"), # values=c("White", "#707070", "#00b8ff", "yellow", "Lightblue"), name = "Item")+ scale_fill_manual(breaks = c("Exposure tank", "Experimental tank", "Crab box", "Speaker"), values=c("Lightblue", "white", "#7575ff", "#00b8ff"), name = "Item")+ # mussel "#707070" scale_color_manual(breaks = c("Valve gape monitor", "Cable", "Water level", "Mesh"), values=c("#D98594", "Grey", "darkblue", "Darkgreen"), name = NULL)+ scale_x_continuous(breaks=seq(0,50,10), limits = c(-2.2, 52.2))+ scale_y_continuous(breaks=seq(0,50,10))+coord_cartesian(ylim=c(0, 50))+ guides(fill = guide_legend(order = 1),col = guide_legend(order = 2))+ theme_bw()+theme(legend.margin = margin(-.2,0,-.3,0, unit="cm")) p2 require(gridExtra) # Get legend g_legend<-function(a.gplot){ tmp <- ggplot_gtable(ggplot_build(a.gplot)) leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box") legend <- tmp$grobs[[leg]] return(legend)} mylegend<-g_legend(p2) # Side and top view next to each other require(gridExtra) overview1 <- grid.arrange(p2+theme(legend.position="none"), mylegend, ncol = 2, widths = c(0.585,0.415)) overview <- grid.arrange(p1+theme(legend.position="none"), overview1, nrow = 2, heights = c(0.5,0.5), top = "Experimental arena") ggsave('Figures_accepted_MS/Figure_1_set-up.tiff', overview, tiff(), units = "in", width = 6.3, height = 7.5, dpi = 600)