Mercurial > repos > greg > insect_phenology_model
comparison utils.R @ 59:892cf703be62 draft
Uploaded
author | greg |
---|---|
date | Wed, 21 Nov 2018 11:42:37 -0500 |
parents | 927321ed0322 |
children | 393085589438 |
comparison
equal
deleted
inserted
replaced
58:2194155309f4 | 59:892cf703be62 |
---|---|
94 } else { | 94 } else { |
95 return(365); | 95 return(365); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm=0, append_start_doy_norm=0, date_interval=FALSE) { | 99 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) { |
100 # Generate a list of ticks and labels for plotting the x axis. | 100 # Generate a list of ticks and labels for plotting the x axis. |
101 if (prepend_end_doy_norm > 0) { | 101 if (prepend_end_doy_norm > 0) { |
102 prepend_end_norm_row = which(temperature_data_frame$DOY==prepend_end_doy_norm); | 102 prepend_end_norm_row = which(temperature_data_frame$DOY==prepend_end_doy_norm); |
103 } else { | 103 } else { |
104 prepend_end_norm_row = 0; | 104 prepend_end_norm_row = 0; |
105 } | 105 } |
106 if (append_start_doy_norm > 0) { | 106 if (append_start_doy_norm > 0) { |
107 append_start_norm_row = which(temperature_data_frame$DOY==append_start_doy_norm); | 107 append_start_norm_row = which(temperature_data_frame$DOY==append_start_doy_norm); |
108 } else { | 108 } else { |
109 append_start_norm_row = 0; | 109 append_start_norm_row = 0; |
110 } | |
111 if (is.null(doy_zero_insects)) { | |
112 zero_insects_row = 0; | |
113 } else { | |
114 zero_insects_row = which(temperature_data_frame$DOY==doy_zero_insects); | |
110 } | 115 } |
111 num_rows = dim(temperature_data_frame)[1]; | 116 num_rows = dim(temperature_data_frame)[1]; |
112 tick_labels = list(); | 117 tick_labels = list(); |
113 ticks = list(); | 118 ticks = list(); |
114 current_month_label = NULL; | 119 current_month_label = NULL; |
128 month_label = month.abb[as.integer(month)]; | 133 month_label = month.abb[as.integer(month)]; |
129 day = as.integer(items[3]); | 134 day = as.integer(items[3]); |
130 doy = as.integer(temperature_data_frame$DOY[i]); | 135 doy = as.integer(temperature_data_frame$DOY[i]); |
131 # We're plotting the entire year, so ticks will | 136 # We're plotting the entire year, so ticks will |
132 # occur on Sundays and the first of each month. | 137 # occur on Sundays and the first of each month. |
133 if (i == prepend_end_norm_row) { | 138 if (i == zero_insects_row) { |
134 # Add a tick for the end of the 30 year normnals data | 139 # Add a tick for the day on which the number of insects |
135 # that was prepended to the year-to-date data. | 140 # per replication is 0. |
136 label_str = "End prepended 30 year normals"; | 141 label_str = "Number insects is 0"; |
137 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) | 142 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); |
138 ticks[tick_index] = i; | 143 ticks[tick_index] = i; |
139 if (date_interval) { | 144 if (date_interval) { |
140 # Append the day to label_str | 145 # Append the day to label_str |
141 tick_labels[tick_index] = paste(label_str, day, sep=" "); | 146 tick_labels[tick_index] = paste(label_str, day, sep=" "); |
142 } else { | 147 } else { |
143 tick_labels[tick_index] = label_str; | 148 tick_labels[tick_index] = label_str; |
144 } | 149 } |
145 last_tick = i; | 150 last_tick = i; |
151 } else if (i == prepend_end_norm_row) { | |
152 # Add a tick for the end of the 30 year normnals data | |
153 # that was prepended to the year-to-date data. | |
154 label_str = "End prepended 30 year normals"; | |
155 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); | |
156 ticks[tick_index] = i; | |
157 if (date_interval) { | |
158 # Append the day to label_str | |
159 tick_labels[tick_index] = paste(label_str, day, sep=" "); | |
160 } else { | |
161 tick_labels[tick_index] = label_str; | |
162 } | |
163 last_tick = i; | |
146 } else if (doy == append_start_doy_norm) { | 164 } else if (doy == append_start_doy_norm) { |
147 # Add a tick for the start of the 30 year normnals data | 165 # Add a tick for the start of the 30 year normnals data |
148 # that was appended to the year-to-date data. | 166 # that was appended to the year-to-date data. |
149 label_str = "Start appended 30 year normals"; | 167 label_str = "Start appended 30 year normals"; |
150 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) | 168 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); |
151 ticks[tick_index] = i; | 169 ticks[tick_index] = i; |
152 if (!identical(current_month_label, month_label)) { | 170 if (!identical(current_month_label, month_label)) { |
153 # Append the month to label_str. | 171 # Append the month to label_str. |
154 label_str = paste(label_str, month_label, spe=" "); | 172 label_str = paste(label_str, month_label, spe=" "); |
155 current_month_label = month_label; | 173 current_month_label = month_label; |
161 tick_labels[tick_index] = label_str; | 179 tick_labels[tick_index] = label_str; |
162 last_tick = i; | 180 last_tick = i; |
163 } else if (i==num_rows) { | 181 } else if (i==num_rows) { |
164 # Add a tick for the last day of the year. | 182 # Add a tick for the last day of the year. |
165 label_str = ""; | 183 label_str = ""; |
166 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) | 184 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); |
167 ticks[tick_index] = i; | 185 ticks[tick_index] = i; |
168 if (!identical(current_month_label, month_label)) { | 186 if (!identical(current_month_label, month_label)) { |
169 # Append the month to label_str. | 187 # Append the month to label_str. |
170 label_str = month_label; | 188 label_str = month_label; |
171 current_month_label = month_label; | 189 current_month_label = month_label; |
176 } | 194 } |
177 tick_labels[tick_index] = label_str; | 195 tick_labels[tick_index] = label_str; |
178 } else { | 196 } else { |
179 if (!identical(current_month_label, month_label)) { | 197 if (!identical(current_month_label, month_label)) { |
180 # Add a tick for the month. | 198 # Add a tick for the month. |
181 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep) | 199 tick_index = get_tick_index(i, last_tick, ticks, tick_labels, tick_sep); |
182 ticks[tick_index] = i; | 200 ticks[tick_index] = i; |
183 if (date_interval) { | 201 if (date_interval) { |
184 # Append the day to the month. | 202 # Append the day to the month. |
185 tick_labels[tick_index] = paste(month_label, day, sep=" "); | 203 tick_labels[tick_index] = paste(month_label, day, sep=" "); |
186 } else { | 204 } else { |