Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 34:7aa848b0e55c draft
Uploaded
author | greg |
---|---|
date | Mon, 19 Mar 2018 14:49:05 -0400 |
parents | ef6aa8c21729 |
children | 29ec818b1c29 |
comparison
equal
deleted
inserted
replaced
33:ef5add7dea47 | 34:7aa848b0e55c |
---|---|
16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"), | 16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"), |
17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"), | 17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"), |
18 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"), | 18 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"), |
19 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"), | 19 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"), |
20 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"), | 20 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"), |
21 make_option(c("--output_combined"), action="store", dest="output_combined", help="Dataset containing analyzed data for combined generations"), | |
22 make_option(c("--output_f1"), action="store", dest="output_f1", default=NULL, help="Dataset containing analyzed data for generation F1"), | |
23 make_option(c("--output_f2"), action="store", dest="output_f2", default=NULL, help="Dataset containing analyzed data for generation F2"), | |
24 make_option(c("--output_p"), action="store", dest="output_p", default=NULL, help="Dataset containing analyzed data for generation P"), | |
25 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"), | 21 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"), |
26 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"), | 22 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"), |
27 make_option(c("--plot_generations_separately"), action="store", dest="plot_generations_separately", help="Plot Plot P, F1 and F2 as separate lines or pool across them"), | 23 make_option(c("--plot_generations_separately"), action="store", dest="plot_generations_separately", help="Plot Plot P, F1 and F2 as separate lines or pool across them"), |
28 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"), | 24 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"), |
29 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"), | 25 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"), |
64 # Reset the column names with the additional column for later access. | 60 # Reset the column names with the additional column for later access. |
65 colnames(data_frame) = append(current_column_names, new_column_name); | 61 colnames(data_frame) = append(current_column_names, new_column_name); |
66 return(data_frame); | 62 return(data_frame); |
67 } | 63 } |
68 | 64 |
69 get_date_labels = function(temperature_data_frame, num_rows) { | 65 get_x_axis_ticks_and_labels = function(temperature_data_frame, num_rows) { |
70 # Keep track of the years to see if spanning years. | 66 # Keep track of the years to see if spanning years. |
71 month_labels = list(); | 67 month_labels = list(); |
68 ticks = list(); | |
72 current_month_label = NULL; | 69 current_month_label = NULL; |
73 for (i in 1:num_rows) { | 70 for (i in 1:num_rows) { |
74 # Get the year and month from the date which | 71 # Get the year and month from the date which |
75 # has the format YYYY-MM-DD. | 72 # has the format YYYY-MM-DD. |
76 date = format(temperature_data_frame$DATE[i]); | 73 date = format(temperature_data_frame$DATE[i]); |
74 # Get the month label. | |
77 items = strsplit(date, "-")[[1]]; | 75 items = strsplit(date, "-")[[1]]; |
78 month = items[2]; | 76 month = items[2]; |
79 month_label = month.abb[as.integer(month)]; | 77 month_label = month.abb[as.integer(month)]; |
80 if (!identical(current_month_label, month_label)) { | 78 if (!identical(current_month_label, month_label)) { |
79 # Add an x-axis tick for the month. | |
80 ticks[length(ticks)+1] = i; | |
81 month_labels[length(month_labels)+1] = month_label; | 81 month_labels[length(month_labels)+1] = month_label; |
82 current_month_label = month_label; | 82 current_month_label = month_label; |
83 } | 83 } |
84 } | 84 # Get the day. |
85 return(c(unlist(month_labels))); | 85 day = weekdays(as.Date(date)); |
86 if (day=="Sunday") { | |
87 # Add an x-axis tick if we're on a Sunday. | |
88 ticks[length(ticks)+1] = i; | |
89 # Add a blank month label so it is not displayed. | |
90 month_labels[length(month_labels)+1] = ""; | |
91 } | |
92 } | |
93 return(list(ticks, month_labels)); | |
86 } | 94 } |
87 | 95 |
88 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) { | 96 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) { |
89 if (!is.null(life_stage_nymph)) { | 97 if (!is.null(life_stage_nymph)) { |
90 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); | 98 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); |
94 file_name = paste(lsi, tolower(life_stage_adult), base_name, sep="_"); | 102 file_name = paste(lsi, tolower(life_stage_adult), base_name, sep="_"); |
95 } else { | 103 } else { |
96 lsi = get_life_stage_index(life_stage); | 104 lsi = get_life_stage_index(life_stage); |
97 file_name = paste(lsi, base_name, sep="_"); | 105 file_name = paste(lsi, base_name, sep="_"); |
98 } | 106 } |
99 file_path = paste("output_dir", file_name, sep="/"); | 107 file_path = paste("output_plots_dir", file_name, sep="/"); |
100 return(file_path); | 108 return(file_path); |
101 } | 109 } |
102 | 110 |
103 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) { | 111 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) { |
104 # Name collection elements so that they | 112 # Name collection elements so that they |
263 temperature_data_frame = add_daylight_length(temperature_data_frame, num_rows); | 271 temperature_data_frame = add_daylight_length(temperature_data_frame, num_rows); |
264 } | 272 } |
265 return(temperature_data_frame); | 273 return(temperature_data_frame); |
266 } | 274 } |
267 | 275 |
268 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, | 276 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, |
269 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, | 277 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, |
270 life_stages_adult=NULL, life_stages_nymph=NULL) { | 278 life_stages_adult=NULL, life_stages_nymph=NULL) { |
271 if (chart_type=="pop_size_by_life_stage") { | 279 if (chart_type=="pop_size_by_life_stage") { |
272 if (life_stage=="Total") { | 280 if (life_stage=="Total") { |
273 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); | 281 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); |
275 columns = c(4, 2, 1); | 283 columns = c(4, 2, 1); |
276 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); | 284 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); |
277 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); | 285 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); |
278 lines(days, group2, lwd=2, lty=1, col=2); | 286 lines(days, group2, lwd=2, lty=1, col=2); |
279 lines(days, group3, lwd=2, lty=1, col=4); | 287 lines(days, group3, lwd=2, lty=1, col=4); |
280 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels); | 288 axis(side=1, at=ticks, labels=date_labels); |
281 axis(2, cex.axis=3); | 289 axis(side=2); |
282 if (plot_std_error=="yes") { | 290 if (plot_std_error=="yes") { |
283 # Standard error for group. | 291 # Standard error for group. |
284 lines(days, group+group_std_error, lty=2); | 292 lines(days, group+group_std_error, lty=2); |
285 lines(days, group-group_std_error, lty=2); | 293 lines(days, group-group_std_error, lty=2); |
286 # Standard error for group2. | 294 # Standard error for group2. |
306 legend_text = c(paste(life_stages_adult, life_stage, sep=" ")); | 314 legend_text = c(paste(life_stages_adult, life_stage, sep=" ")); |
307 columns = c(1); | 315 columns = c(1); |
308 } | 316 } |
309 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); | 317 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); |
310 legend("topleft", legend_text, lty=c(1), col="black", cex=3); | 318 legend("topleft", legend_text, lty=c(1), col="black", cex=3); |
311 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels); | 319 axis(side=1, at=ticks, labels=date_labels); |
312 axis(2, cex.axis=3); | 320 axis(side=2); |
313 if (plot_std_error=="yes") { | 321 if (plot_std_error=="yes") { |
314 # Standard error for group. | 322 # Standard error for group. |
315 lines(days, group+group_std_error, lty=2); | 323 lines(days, group+group_std_error, lty=2); |
316 lines(days, group-group_std_error, lty=2); | 324 lines(days, group-group_std_error, lty=2); |
317 } | 325 } |
331 columns = c(1, 2, 4); | 339 columns = c(1, 2, 4); |
332 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); | 340 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3); |
333 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); | 341 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3); |
334 lines(days, group2, lwd=2, lty=1, col=2); | 342 lines(days, group2, lwd=2, lty=1, col=2); |
335 lines(days, group3, lwd=2, lty=1, col=4); | 343 lines(days, group3, lwd=2, lty=1, col=4); |
336 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels); | 344 axis(side=1, at=ticks, labels=date_labels); |
337 axis(2, cex.axis=3); | 345 axis(side=2); |
338 if (plot_std_error=="yes") { | 346 if (plot_std_error=="yes") { |
339 # Standard error for group. | 347 # Standard error for group. |
340 lines(days, group+group_std_error, lty=2); | 348 lines(days, group+group_std_error, lty=2); |
341 lines(days, group-group_std_error, lty=2); | 349 lines(days, group-group_std_error, lty=2); |
342 # Standard error for group2. | 350 # Standard error for group2. |
362 temperature_data_frame_P = data.frame(temperature_data_frame); | 370 temperature_data_frame_P = data.frame(temperature_data_frame); |
363 temperature_data_frame_F1 = data.frame(temperature_data_frame); | 371 temperature_data_frame_F1 = data.frame(temperature_data_frame); |
364 temperature_data_frame_F2 = data.frame(temperature_data_frame); | 372 temperature_data_frame_F2 = data.frame(temperature_data_frame); |
365 } | 373 } |
366 # Get the date labels for plots. | 374 # Get the date labels for plots. |
367 date_labels = get_date_labels(temperature_data_frame, opt$num_days); | 375 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, opt$num_days); |
376 ticks = c(unlist(ticks_and_labels[1])); | |
377 date_labels = c(unlist(ticks_and_labels[2])); | |
368 # All latitude values are the same, so get the value for plots from the first row. | 378 # All latitude values are the same, so get the value for plots from the first row. |
369 latitude = temperature_data_frame$LATITUDE[1]; | 379 latitude = temperature_data_frame$LATITUDE[1]; |
370 # Determine the specified life stages for processing. | 380 # Determine the specified life stages for processing. |
371 # Split life_stages into a list of strings for plots. | 381 # Split life_stages into a list of strings for plots. |
372 life_stages_str = as.character(opt$life_stages); | 382 life_stages_str = as.character(opt$life_stages); |
1254 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults.std_error, "TOTALADULT-F2-SE"); | 1264 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults.std_error, "TOTALADULT-F2-SE"); |
1255 } | 1265 } |
1256 } | 1266 } |
1257 | 1267 |
1258 # Save the analyzed data for combined generations. | 1268 # Save the analyzed data for combined generations. |
1259 write.csv(temperature_data_frame, file=opt$output_combined, row.names=F); | 1269 file_path = paste("output_data_dir", "04_combined_generations.csv", sep="/"); |
1270 write.csv(temperature_data_frame, file=file_path, row.names=F); | |
1260 if (plot_generations_separately) { | 1271 if (plot_generations_separately) { |
1261 # Save the analyzed data for generation P. | 1272 # Save the analyzed data for generation P. |
1262 write.csv(temperature_data_frame_P, file=opt$output_p, row.names=F); | 1273 file_path = paste("output_data_dir", "01_generation_P.csv", sep="/"); |
1274 write.csv(temperature_data_frame_P, file=file_path, row.names=F); | |
1263 # Save the analyzed data for generation F1. | 1275 # Save the analyzed data for generation F1. |
1264 write.csv(temperature_data_frame_F1, file=opt$output_f1, row.names=F); | 1276 file_path = paste("output_data_dir", "02_generation_F1.csv", sep="/"); |
1277 write.csv(temperature_data_frame_F1, file=file_path, row.names=F); | |
1265 # Save the analyzed data for generation F2. | 1278 # Save the analyzed data for generation F2. |
1266 write.csv(temperature_data_frame_F2, file=opt$output_f2, row.names=F); | 1279 file_path = paste("output_data_dir", "03_generation_F2.csv", sep="/"); |
1280 write.csv(temperature_data_frame_F2, file=file_path, row.names=F); | |
1267 } | 1281 } |
1268 # Display the total number of days in the Galaxy history item blurb. | 1282 # Display the total number of days in the Galaxy history item blurb. |
1269 cat("Number of days: ", opt$num_days, "\n"); | 1283 cat("Number of days: ", opt$num_days, "\n"); |
1270 # Information needed for plots plots. | 1284 # Information needed for plots plots. |
1271 days = c(1:opt$num_days); | 1285 days = c(1:opt$num_days); |
1280 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf") | 1294 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf") |
1281 pdf(file=file_path, width=20, height=30, bg="white"); | 1295 pdf(file=file_path, width=20, height=30, bg="white"); |
1282 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1296 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1283 # Egg population size by generation. | 1297 # Egg population size by generation. |
1284 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100; | 1298 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100; |
1285 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1299 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1286 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, | 1300 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, |
1287 group3_std_error=F2_eggs.std_error); | 1301 group3_std_error=F2_eggs.std_error); |
1288 # Turn off device driver to flush output. | 1302 # Turn off device driver to flush output. |
1289 dev.off(); | 1303 dev.off(); |
1290 } else if (life_stage == "Nymph") { | 1304 } else if (life_stage == "Nymph") { |
1320 group2 = F1_total_nymphs; | 1334 group2 = F1_total_nymphs; |
1321 group2_std_error = F1_total_nymphs.std_error; | 1335 group2_std_error = F1_total_nymphs.std_error; |
1322 group3 = F2_total_nymphs; | 1336 group3 = F2_total_nymphs; |
1323 group3_std_error = F2_total_nymphs.std_error; | 1337 group3_std_error = F2_total_nymphs.std_error; |
1324 } | 1338 } |
1325 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1339 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1326 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, | 1340 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, |
1327 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph); | 1341 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph); |
1328 # Turn off device driver to flush output. | 1342 # Turn off device driver to flush output. |
1329 dev.off(); | 1343 dev.off(); |
1330 } | 1344 } |
1370 group2 = F1_total_adults; | 1384 group2 = F1_total_adults; |
1371 group2_std_error = F1_total_adults.std_error; | 1385 group2_std_error = F1_total_adults.std_error; |
1372 group3 = F2_total_adults; | 1386 group3 = F2_total_adults; |
1373 group3_std_error = F2_total_adults.std_error; | 1387 group3_std_error = F2_total_adults.std_error; |
1374 } | 1388 } |
1375 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1389 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1376 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, | 1390 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, |
1377 group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult); | 1391 group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult); |
1378 # Turn off device driver to flush output. | 1392 # Turn off device driver to flush output. |
1379 dev.off(); | 1393 dev.off(); |
1380 } | 1394 } |
1386 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf") | 1400 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf") |
1387 pdf(file=file_path, width=20, height=30, bg="white"); | 1401 pdf(file=file_path, width=20, height=30, bg="white"); |
1388 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1402 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1389 # Total population size by generation. | 1403 # Total population size by generation. |
1390 maxval = max(P+F1+F2) + 100; | 1404 maxval = max(P+F1+F2) + 100; |
1391 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1405 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1392 opt$replications, life_stage, group=P, group_std_error=P.std_error, group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error); | 1406 opt$replications, life_stage, group=P, group_std_error=P.std_error, group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error); |
1393 # Turn off device driver to flush output. | 1407 # Turn off device driver to flush output. |
1394 dev.off(); | 1408 dev.off(); |
1395 } | 1409 } |
1396 } | 1410 } |
1402 file_path = get_file_path(life_stage, "egg_pop.pdf") | 1416 file_path = get_file_path(life_stage, "egg_pop.pdf") |
1403 pdf(file=file_path, width=20, height=30, bg="white"); | 1417 pdf(file=file_path, width=20, height=30, bg="white"); |
1404 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1418 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1405 # Egg population size. | 1419 # Egg population size. |
1406 maxval = max(eggs+eggs.std_error) + 100; | 1420 maxval = max(eggs+eggs.std_error) + 100; |
1407 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1421 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1408 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error); | 1422 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error); |
1409 # Turn off device driver to flush output. | 1423 # Turn off device driver to flush output. |
1410 dev.off(); | 1424 dev.off(); |
1411 } else if (life_stage == "Nymph") { | 1425 } else if (life_stage == "Nymph") { |
1412 for (life_stage_nymph in life_stages_nymph) { | 1426 for (life_stage_nymph in life_stages_nymph) { |
1427 # Old nymph population size. | 1441 # Old nymph population size. |
1428 group = old_nymphs; | 1442 group = old_nymphs; |
1429 group_std_error = old_nymphs.std_error; | 1443 group_std_error = old_nymphs.std_error; |
1430 } | 1444 } |
1431 maxval = max(group+group_std_error) + 100; | 1445 maxval = max(group+group_std_error) + 100; |
1432 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1446 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1433 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_nymph=life_stage_nymph); | 1447 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_nymph=life_stage_nymph); |
1434 # Turn off device driver to flush output. | 1448 # Turn off device driver to flush output. |
1435 dev.off(); | 1449 dev.off(); |
1436 } | 1450 } |
1437 } else if (life_stage == "Adult") { | 1451 } else if (life_stage == "Adult") { |
1457 # Diapausing adult population size. | 1471 # Diapausing adult population size. |
1458 group = diapausing_adults; | 1472 group = diapausing_adults; |
1459 group_std_error = diapausing_adults.std_error | 1473 group_std_error = diapausing_adults.std_error |
1460 } | 1474 } |
1461 maxval = max(group+group_std_error) + 100; | 1475 maxval = max(group+group_std_error) + 100; |
1462 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1476 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1463 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_adult=life_stage_adult); | 1477 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_adult=life_stage_adult); |
1464 # Turn off device driver to flush output. | 1478 # Turn off device driver to flush output. |
1465 dev.off(); | 1479 dev.off(); |
1466 } | 1480 } |
1467 } else if (life_stage == "Total") { | 1481 } else if (life_stage == "Total") { |
1470 file_path = get_file_path(life_stage, "total_pop.pdf") | 1484 file_path = get_file_path(life_stage, "total_pop.pdf") |
1471 pdf(file=file_path, width=20, height=30, bg="white"); | 1485 pdf(file=file_path, width=20, height=30, bg="white"); |
1472 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1486 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1473 # Total population size. | 1487 # Total population size. |
1474 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100; | 1488 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100; |
1475 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1489 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1476 opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error, group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, | 1490 opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error, group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, |
1477 group3_std_error=eggs.std_error); | 1491 group3_std_error=eggs.std_error); |
1478 # Turn off device driver to flush output. | 1492 # Turn off device driver to flush output. |
1479 dev.off(); | 1493 dev.off(); |
1480 } | 1494 } |