Skip to content

Instantly share code, notes, and snippets.

@joshcutler
Created October 17, 2011 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshcutler/1293829 to your computer and use it in GitHub Desktop.
Save joshcutler/1293829 to your computer and use it in GitHub Desktop.
Resource consumption graph
rm(list = ls()) #Clear the workspace
library(ggplot2)
time = seq(1:1000)
starting_population = 2
reproduction_rate = 1.0192
population = cbind(time, starting_population*reproduction_rate^time)
starting_resources = population[time==length(time)-1][2]
resources = cbind(time, starting_resources - population[,2])
data = as.data.frame(rbind(population, resources))
# data set indicator
data$ds <- factor(rep(1:2, c(length(time), length(time))))
data$Legend <- factor(rep(c("Population", "Resources"), c(length(time), length(time))))
plot1 = ggplot(data, aes(x=time, y=V2, group=ds, color=Legend)) +
geom_line(factor=data$ds) +
scale_y_continuous('Count', limits=c(0, starting_resources)) +
scale_x_continuous("Time")
print(plot1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment