Created
October 17, 2011 21:09
-
-
Save joshcutler/1293829 to your computer and use it in GitHub Desktop.
Resource consumption graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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