Mercurial > repos > greg > insect_phenology_model
diff utils.R @ 59:892cf703be62 draft
Uploaded
author | greg |
---|---|
date | Wed, 21 Nov 2018 11:42:37 -0500 |
parents | 927321ed0322 |
children | 393085589438 |
line wrap: on
line diff
--- a/utils.R Fri Nov 09 13:05:31 2018 -0500 +++ b/utils.R Wed Nov 21 11:42:37 2018 -0500 @@ -96,7 +96,7 @@ } } -get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm=0, append_start_doy_norm=0, date_interval=FALSE) { +get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm=0, append_start_doy_norm=0, date_interval=FALSE, doy_zero_insects=NULL) { # Generate a list of ticks and labels for plotting the x axis. if (prepend_end_doy_norm > 0) { prepend_end_norm_row = which(temperature_data_frame$DOY==prepend_end_doy_norm); @@ -108,6 +108,11 @@ } else { append_start_norm_row = 0; } + if (is.null(doy_zero_insects)) { + zero_insects_row = 0; + } else { + zero_insects_row = which(temperature_data_frame$DOY==doy_zero_insects); + } num_rows = dim(temperature_data_frame)[1]; tick_labels = list(); ticks = list(); @@ -130,11 +135,24 @@ doy = as.integer(temperature_data_frame$DOY[i]); # We're plotting the entire year, so ticks will # occur on Sundays and the first of each month. - if (i == prepend_end_norm_row) { + if (i == zero_insects_row) { + # Add a tick for the day on which the number of insects + # per replication is 0. + label_str = "Number insects is 0"; + tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); + ticks[tick_index] = i; + if (date_interval) { + # Append the day to label_str + tick_labels[tick_index] = paste(label_str, day, sep=" "); + } else { + tick_labels[tick_index] = label_str; + } + last_tick = i; + } else if (i == prepend_end_norm_row) { # Add a tick for the end of the 30 year normnals data # that was prepended to the year-to-date data. label_str = "End prepended 30 year normals"; - tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) + tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); ticks[tick_index] = i; if (date_interval) { # Append the day to label_str @@ -147,7 +165,7 @@ # Add a tick for the start of the 30 year normnals data # that was appended to the year-to-date data. label_str = "Start appended 30 year normals"; - tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) + tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); ticks[tick_index] = i; if (!identical(current_month_label, month_label)) { # Append the month to label_str. @@ -163,7 +181,7 @@ } else if (i==num_rows) { # Add a tick for the last day of the year. label_str = ""; - tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) + tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); ticks[tick_index] = i; if (!identical(current_month_label, month_label)) { # Append the month to label_str. @@ -178,7 +196,7 @@ } else { if (!identical(current_month_label, month_label)) { # Add a tick for the month. - tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) + tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); ticks[tick_index] = i; if (date_interval) { # Append the day to the month.