Student-solutions/Ryan

From Earlham CS Department
Revision as of 23:32, 24 October 2012 by Rjlake10 (talk | contribs)
Jump to navigation Jump to search

Science Visualizations

R Visualization

time <- c(2*0:10,21)
init <- 1
fin <- 220
i <- init:fin
weight0 <- ifelse(ChickWeight[i,2] == 0, ChickWeight[i,1], NA)
weight2 <- ifelse(ChickWeight[i,2] == 2, ChickWeight[i,1], NA)
weight4 <- ifelse(ChickWeight[i,2] == 4, ChickWeight[i,1], NA)
weight6 <- ifelse(ChickWeight[i,2] == 6, ChickWeight[i,1], NA)
weight8 <- ifelse(ChickWeight[i,2] == 8, ChickWeight[i,1], NA)
weight10 <- ifelse(ChickWeight[i,2] == 10, ChickWeight[i,1], NA)
weight12 <- ifelse(ChickWeight[i,2] == 12, ChickWeight[i,1], NA)
weight14 <- ifelse(ChickWeight[i,2] == 14, ChickWeight[i,1], NA)
weight16 <- ifelse(ChickWeight[i,2] == 16, ChickWeight[i,1], NA)
weight18 <- ifelse(ChickWeight[i,2] == 18, ChickWeight[i,1], NA)
weight20 <- ifelse(ChickWeight[i,2] == 20, ChickWeight[i,1], NA)
weight21 <- ifelse(ChickWeight[i,2] == 21, ChickWeight[i,1], NA)
weights <- array(c(weight0, weight2, weight4, weight6, weight8, weight10, weight12, weight14, weight16, weight18, weight20, weight21), c(fin-init+1, 12))
meanweight <- colMeans(weights, na.rm = TRUE, dims = 1)
plot(time, meanweight, xlim=c(0,21),ylim=c(40,271),main="Mean Chick Weights for Four Diets over Twenty-One Days",type="b")
init <- 221
fin <- 340
i <- init:fin
weight0 <- ifelse(ChickWeight[i,2] == 0, ChickWeight[i,1], NA)
weight2 <- ifelse(ChickWeight[i,2] == 2, ChickWeight[i,1], NA)
weight4 <- ifelse(ChickWeight[i,2] == 4, ChickWeight[i,1], NA)
weight6 <- ifelse(ChickWeight[i,2] == 6, ChickWeight[i,1], NA)
weight8 <- ifelse(ChickWeight[i,2] == 8, ChickWeight[i,1], NA)
weight10 <- ifelse(ChickWeight[i,2] == 10, ChickWeight[i,1], NA)
weight12 <- ifelse(ChickWeight[i,2] == 12, ChickWeight[i,1], NA)
weight14 <- ifelse(ChickWeight[i,2] == 14, ChickWeight[i,1], NA)
weight16 <- ifelse(ChickWeight[i,2] == 16, ChickWeight[i,1], NA)
weight18 <- ifelse(ChickWeight[i,2] == 18, ChickWeight[i,1], NA)
weight20 <- ifelse(ChickWeight[i,2] == 20, ChickWeight[i,1], NA)
weight21 <- ifelse(ChickWeight[i,2] == 21, ChickWeight[i,1], NA)
weights <- array(c(weight0, weight2, weight4, weight6, weight8, weight10, weight12, weight14, weight16, weight18, weight20, weight21), c(fin-init+1, 12))
meanweight <- colMeans(weights, na.rm = TRUE, dims = 1)
points(time, meanweight, pch=2, type="b")
init <- 341
fin <- 460
i <- init:fin
weight0 <- ifelse(ChickWeight[i,2] == 0, ChickWeight[i,1], NA)
weight2 <- ifelse(ChickWeight[i,2] == 2, ChickWeight[i,1], NA)
weight4 <- ifelse(ChickWeight[i,2] == 4, ChickWeight[i,1], NA)
weight6 <- ifelse(ChickWeight[i,2] == 6, ChickWeight[i,1], NA)
weight8 <- ifelse(ChickWeight[i,2] == 8, ChickWeight[i,1], NA)
weight10 <- ifelse(ChickWeight[i,2] == 10, ChickWeight[i,1], NA)
weight12 <- ifelse(ChickWeight[i,2] == 12, ChickWeight[i,1], NA)
weight14 <- ifelse(ChickWeight[i,2] == 14, ChickWeight[i,1], NA)
weight16 <- ifelse(ChickWeight[i,2] == 16, ChickWeight[i,1], NA)
weight18 <- ifelse(ChickWeight[i,2] == 18, ChickWeight[i,1], NA)
weight20 <- ifelse(ChickWeight[i,2] == 20, ChickWeight[i,1], NA)
weight21 <- ifelse(ChickWeight[i,2] == 21, ChickWeight[i,1], NA)
weights <- array(c(weight0, weight2, weight4, weight6, weight8, weight10, weight12, weight14, weight16, weight18, weight20, weight21), c(fin-init+1, 12))
meanweight <- colMeans(weights, na.rm = TRUE, dims = 1)
points(time, meanweight, pch=3, type="b")
init <- 461
fin <- 578
i <- init:fin
weight0 <- ifelse(ChickWeight[i,2] == 0, ChickWeight[i,1], NA)
weight2 <- ifelse(ChickWeight[i,2] == 2, ChickWeight[i,1], NA)
weight4 <- ifelse(ChickWeight[i,2] == 4, ChickWeight[i,1], NA)
weight6 <- ifelse(ChickWeight[i,2] == 6, ChickWeight[i,1], NA)
weight8 <- ifelse(ChickWeight[i,2] == 8, ChickWeight[i,1], NA)
weight10 <- ifelse(ChickWeight[i,2] == 10, ChickWeight[i,1], NA)
weight12 <- ifelse(ChickWeight[i,2] == 12, ChickWeight[i,1], NA)
weight14 <- ifelse(ChickWeight[i,2] == 14, ChickWeight[i,1], NA)
weight16 <- ifelse(ChickWeight[i,2] == 16, ChickWeight[i,1], NA)
weight18 <- ifelse(ChickWeight[i,2] == 18, ChickWeight[i,1], NA)
weight20 <- ifelse(ChickWeight[i,2] == 20, ChickWeight[i,1], NA)
weight21 <- ifelse(ChickWeight[i,2] == 21, ChickWeight[i,1], NA)
weights <- array(c(weight0, weight2, weight4, weight6, weight8, weight10, weight12, weight14, weight16, weight18, weight20, weight21), c(fin-init+1, 12))
meanweight <- colMeans(weights, na.rm = TRUE, dims = 1)
points(time, meanweight, pch=4, type="b")
points(2,250)
points(2,235,pch=2)
points(2,220,pch=3)
points(2,205,pch=4)
text(3.5,250,"Diet 1")
text(3.5,235,"Diet 2")
text(3.5,220,"Diet 3")
text(3.5,205,"Diet 4")
#Finished!