plotSpaghetti<-function(X){
fill <- color <- "meow_realm"
#Spaghetti plots
colourCount = length(unique(X$meow_realm))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
g <- ggplot(X, aes(x = x, y = y, colour = meow_realm)) +
geom_point(aes(x = x, y = y, colour = meow_realm),
size = 2, data = subset(X, method == "observed"))
g <- g + geom_ribbon(aes(ymin = y.lwr, ymax = y.upr,
fill = meow_realm, colour = NULL, group = label),
alpha = 0.2, data = X)
g <- g + geom_line(aes(x = x, y = y, fill = meow_realm, group = label),
size = 0.5, linetype=1, data = subset(X, method == "interpolated" ))
g <- g +
geom_line(aes(x = x, y = y, fill = meow_realm, group = label),
size = 0.5, linetype=2, data = subset(X, method == "extrapolated" )) +
theme_bw() +
guides(col=guide_legend(nrow=2),linetype = guide_legend(title = "Method"),
colour = guide_legend(title = "Order"), fill = guide_legend(title = "Order"),
shape = guide_legend(title = "Site")) +
theme(legend.position = "bottom", text = element_text(size = 8))
g <- g +
scale_colour_manual(guide = guide_legend(title = ""),
values = colorRampPalette(brewer.pal(9, "Set1"))(colourCount)) +
scale_fill_manual(guide = guide_legend(title = ""),
values = colorRampPalette(brewer.pal(9, "Set1"))(colourCount)) +
guides(fill=F) +
theme(legend.key = element_rect(fill = "white")) +
theme(legend.position="bottom") +
xlab("Number of sequences sampled") +
ylab("Species diversity")
g <- g +
facet_grid(order~meow_realm, scale="free") +
theme(legend.key.size = unit(0.5, "cm")) +
guides(col = guide_legend(nrow = 2, byrow = TRUE))
return(g)
}
plotSpaghetti(inext_est_raw_rar %>% filter(water_depth <= 5, !is.na(meow_realm)))