Skip to content

Instantly share code, notes, and snippets.

@whitead
Last active December 17, 2015 07:29
predatory prey plot in R
data <- read.table("out.txt")
time <- data[,1]
temps <- 20:30
crows <- data[,2:(length(temps) + 1)]
cats <- data[,(length(temps) + 2):ncol(data)]
colors <- colorRampPalette(c("blue", "red")) (length(temps))
cairo_pdf("crows.pdf", width=5, height=7)
par(family="LMRoman10", fg="dark gray", mfrow=c(2,1), mar=c(2,4,0.5,2))
plot(time, crows[,1], ylim=c(min(crows), max(crows)), xlab="", ylab="Crows", lwd=1, col=colors[1], type="l", xaxt="n")
for(i in 2:length(temps)){
lines(time, crows[,i], col=colors[i], ylim=c(min(crows), max(crows)))
}
par(mar=c(5,4,0,2))
plot(time, cats[,1], ylim=c(min(cats), max(cats)), xlab="time", ylab="Cats", lwd=1, col=colors[1], type="l")
for(i in 2:length(temps)){
lines(time, cats[,i], col=colors[i], ylim=c(min(cats), max(cats)))
}
graphics.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment