-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEggHatch.R
618 lines (367 loc) · 26.5 KB
/
EggHatch.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# NOTE TO CONTRIBUTORS: Beyond expanding the functionality of EggHatch there are other potential considerations for its future development. For example:
# we could try and remove as many pacakge dependencies as possible (though this might be quite difficult & ultimately unnecessary);
# we could also imoriove the script below by reducing the number of loops and incorporating piping (i.e., %>%) where possible.
# Object inspection shows that layers are numbered so should be able to access each layer by inputting number also. For example change function
# input to include layer=1(a=4), for example? Maybe a better way to do that? Most sensible way would be to loop through layers and determine
# the index number of the bar for that layer. Removes need for extra input. May need to perform addition or subtraction to values if each layer
# resets index. Investigate.
library(ggplot2)
Example.Data<- data.frame(matrix(vector(), 0, 3, dimnames=list(c(), c("Value", "Variable", "Fill"))), stringsAsFactors=F)
Example.Data[1, ] <- c(80.9, 'Horizontal Pattern','Horizontal Pattern' )
Example.Data[2, ] <- c(67.677777, 'Vertical Pattern','Vertical Pattern' )
Example.Data[3, ] <- c(10.678, 'Mesh HorizVert Pattern','Mesh HorizVert Pattern' )
Example.Data[4,] <- c(95.8, 'Diagonal Pattern 1','Diagonal Pattern 1' )
Example.Data[5,] <- c(67.67, 'Diagonal Pattern 2','Diagonal Pattern 2' )
Example.Data[6,] <- c(58.9, 'Mesh Diagonal Pattern','Mesh Diagonal Pattern' )
Example.Data[7,] <- c(75, 'Mesh HorizVertDiag Pattern','Mesh HorizVertDiag Pattern' )
HighlightDataVert<-Example.Data[2, ]
HighlightHorizontal<-Example.Data[1, ]
HighlightMesh<-Example.Data[3, ]
HighlightHorizontal$Value<-as.numeric(HighlightHorizontal$Value)
Example.Data$Value<-as.numeric(Example.Data$Value)
example_plot<-ggplot(Example.Data, aes(x=Variable, y=Value, fill=factor(Fill))) +
theme_bw() +
theme(legend.position = "none")+
scale_fill_grey(start=.4)+
geom_bar(position='identity', stat="identity", colour="black", width=.86565656)
example_plot
EggHatch <- function(ggplot2_plot, cond.list, width_Man = NULL){
# use this for Relevel
library(Epi)
# default relevel to avoid index issue
ggplot2_plot$data$Variable = Relevel(ggplot2_plot$data$Variable, ref = c(ggplot2_plot$data$Variable))
print("When choosing patterns ensure that scaling does not obscure horizontal lines. Should horizontal lines be obscured consider a different pattern (A, C, D, or any combination of them.)")
# if statement for when no value input in 'fill'
library(stringi)
library(plyr)
library(gtools)
library(stringr)
input_position_dodge<-ggplot2_plot$layers[[1]]$position$width
input_colour<-ggplot2_plot$layers[[1]]$aes_params$colour
fill_value<-ggplot2_plot$layers[[1]]$aes_params$fill
input_size<-ggplot2_plot$theme$rect$size
input_width<-ggplot2_plot$layers[[1]]$geom_params$width
# remove any spaces, tabs etc. from input string
cond.list<-stri_replace_all_charclass(cond.list, "\\p{WHITE_SPACE}", "")
# list of conditions input by users
string_split1<-strsplit(cond.list, ",")[[1]]
# Dataframe shaped to match number of patterns and conditions entries
df <- data.frame(matrix(ncol = 2, nrow = length(string_split1)))
colnames(df) <- c("Pattern", "Condition")
pattern_options <- c("A", "B", "C", "D")
BAR_OUTPUT1<-ggplot2_plot
BAR_OUTPUT<-BAR_OUTPUT1
for (pos in 1:length(string_split1)){
# seperate pattern from input condition into list, dropping '='
cond_patterns <- as.list(strsplit(string_split1[pos], "=")[[1]])
# write values to relevant colomns on current row
df$Pattern[pos]<-cond_patterns[1]
df$Condition[pos]<-cond_patterns[2]
}
# find largest mean value and pass 2% of it
two_percent_of_largest_mean<-((max(unlist(lapply(ggplot2_plot$data$Value,FUN=max)))/100)*2)
# loop around for number of conditions
for (pos in 1:length(df$Condition)){
Condition_Pos=0
# split pattern into individual characters
pattern_split_loop_var<-as.character(df$Pattern[pos])
pattern_split_loop_var<- strsplit(pattern_split_loop_var, "")[[1]]
if(grep("A|B|C|D", df$Pattern[pos], ignore.case=TRUE)){
if ((grepl('A', df$Pattern[pos], ignore.case=TRUE))){
# get 25% of original width
vert_bar_count = (((ggplot2_plot$layers[[1]]$geom_params$width)/100)*10)
Condition_Pos<-as.numeric(df$Condition[pos])
for (i in 1){
if (is.null(fill_value)){
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width=(ggplot2_plot$layers[[1]]$geom_params$width))
}
if (!is.null(fill_value)){
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width=(ggplot2_plot$layers[[1]]$geom_params$width),fill=fill_value)
}
# loop 4 times
for (i in 1:((ggplot2_plot$layers[[1]]$geom_params$width)/vert_bar_count)){
# when calculating the number of times to loop and draw consider making value = bar width
# additionally consider add a verticle line '0' by default. Should get around any
# stepping outside range
# alternative just draw a line on each unit on the x-axis inside bounds of bar: number at given
# point (x-axis label) then either side of number, for example:
# geom_vline(xintercept=c(1.5,2.5, 10.5), linetype="dotted", size=.8)
#
# ensure the Condition_Position value is correct here
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width=(ggplot2_plot$layers[[1]]$geom_params$width)-vert_bar_count, fill='transparent')
vert_bar_count = vert_bar_count + (((ggplot2_plot$layers[[1]]$geom_params$width)/100)*10)#((ggplot2_plot$layers[[1]]$geom_params$width)/4)
}
}
if ((grepl('B', df$Pattern[pos], ignore.case=TRUE))){
point_1_percent_of_current_mean <- ((BAR_OUTPUT$data$Value[Condition_Pos]/100)*.1)
while((BAR_OUTPUT$data$Value[Condition_Pos])>=two_percent_of_largest_mean){
# this breaks while loop to prevent going below x-axis 0
if(((as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-(ggplot2_plot$data$Value[Condition_Pos]/100))<0){
break
}
BAR_OUTPUT$data$Value[Condition_Pos]<-(as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-two_percent_of_largest_mean
# This stops line very close to 0 on y-axis
if(((BAR_OUTPUT$data$Value[Condition_Pos])<((two_percent_of_largest_mean/100)*15))){
break
}
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width, fill='transparent')
}
} # end of sub grepl 'B'
if ((grepl('C', df$Pattern[pos], ignore.case=TRUE))){
# Code for diagonal C
position_input_x<-as.numeric(df$Condition[pos])
position_input_y<-as.numeric(df$Condition[pos])
# half of input width
# when minused from centre of bar point on x-axis
# it gives value at start of bar on x-axis
# inverse true for end of bar width
half_input_width<-input_width/2
ten_perc_input_width<-((input_width/100)*10)
x_axis_min <- position_input_x-half_input_width
x_axis_start_top<-x_axis_min
x_axis_start_bottom<-x_axis_min
x_axis_max <- position_input_x+half_input_width
y_axis_max<- ggplot2_plot$data$Value[position_input_y]
# need to pull the max value from the example_plot the max boundries...
# or caluclate the
z_percent_of_current_mean<-(y_axis_max/100)*10
df_diag <- data.frame(
# start on x-axis-end on x-axis
x = c(x_axis_start_bottom,x_axis_start_top),
# start on y-axis-end on y-axis
y = c(y_axis_max,y_axis_max), Fill='Hope you\'re having a nice day.')
for(i in 1:19){
# run if 2nd x-position is less or equal to rightmost edge of bar
# minus 10% of total input width
if (df_diag$x[2]<(as.character(x_axis_max))){
# 1/10 of unit value in width field
df_diag$x[2]<-df_diag$x[2]+(ten_perc_input_width)
# subtract z percent from 1st y height
df_diag$y[1]<-df_diag$y[1]-(z_percent_of_current_mean)
# draw using current df_diag values
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when less than x_axis_max
# run this code to limit 2nd x-point from moving past rightmost edge of bar
if (df_diag$x[2]==as.character(x_axis_max)){
# drop height of 2nd y-position by z percentage
df_diag$y[2]<-df_diag$y[2]-(z_percent_of_current_mean)
if(df_diag$y[1]<=z_percent_of_current_mean){
df_diag$x[1]<-df_diag$x[1]+ten_perc_input_width
}
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when x_axis_max reached
} # end of for loop 1:19
} # end of sub grepl 'C'
if ((grepl('D', df$Pattern[pos], ignore.case=TRUE))){
# Code for left leaning diagonal 'D'
position_input_x<-as.numeric(df$Condition[pos])
position_input_y<-as.numeric(df$Condition[pos])
# half of input width
# when minused from centre of bar point on x-axis
# it gives value at start of bar on x-axis
# inverse true for end of bar width
half_input_width<-input_width/2
ten_perc_input_width<-((input_width/100)*10)
x_axis_min <- position_input_x-half_input_width
x_axis_max <- position_input_x+half_input_width
y_axis_max<- ggplot2_plot$data$Value[position_input_y]
# need to pull the max value from the example_plot the max boundries...
# or caluclate the
z_percent_of_current_mean<-(y_axis_max/100)*10
df_diag <- data.frame(
# start on x-axis-end on x-axis
x = c(x_axis_max,x_axis_max),
# start on y-axis-end on y-axis
y = c(y_axis_max,y_axis_max), Fill='Hope you\'re having a nice day.')
for(i in 1:19){
# run if 1st x-position is less or equal to leftmost edge of bar
# minus 10% of total input width
if (df_diag$x[2]>(as.character(x_axis_min))){
# 1/10 of unit value in width field
df_diag$x[2]<-df_diag$x[2]-(ten_perc_input_width)
# subtract z percent from 1st y height
df_diag$y[1]<-df_diag$y[1]-(z_percent_of_current_mean)
# draw using current df_diag values
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when less than x_axis_max
# run this code to limit 2nd x-point from moving past rightmost edge of bar
if (df_diag$x[2]==as.character(x_axis_min)){
# drop height of 2nd y-position by z percentage
df_diag$y[2]<-df_diag$y[2]-(z_percent_of_current_mean)
if(df_diag$y[1]<=z_percent_of_current_mean){
df_diag$x[1]<-df_diag$x[1]-ten_perc_input_width
}
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when x_axis_max reached
} # end of for loop 1:19
}
} # end of if grepl 'A'
# This runs code when *only* 'B' in string
if ((!grepl("[^B]", df$Pattern[pos], ignore.case=TRUE))==TRUE){
Condition_Pos<-as.numeric(df$Condition[pos])
one_percent_horiz<-(BAR_OUTPUT$data$Value[Condition_Pos])/100
Twenty_percent_horiz<-(one_percent_horiz*20)
point_1_percent_of_current_mean <- ((BAR_OUTPUT$data$Value[Condition_Pos]/100)*.1)
# draw original bar -> avoids any issue with 'fill' and drawing incorrect height
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width)
# drawing lines (via minusing mean) above 0 on y-axis
while((BAR_OUTPUT$data$Value[Condition_Pos])>=two_percent_of_largest_mean){
# this breaks while loop to prevent going below x-axis 0
if(((as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-(ggplot2_plot$data$Value[Condition_Pos]/100))<0){
break
}
# check null value
if (is.null(fill_value)){
BAR_OUTPUT$data$Value[Condition_Pos]<-(as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-two_percent_of_largest_mean
if(((BAR_OUTPUT$data$Value[Condition_Pos])<((two_percent_of_largest_mean/100)*15))){
break
}
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width)
}
if (!is.null(fill_value)){
BAR_OUTPUT$data$Value[Condition_Pos]<-(as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-two_percent_of_largest_mean
if(((BAR_OUTPUT$data$Value[Condition_Pos])<((two_percent_of_largest_mean/100)*15))){
break
}
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width, fill=fill_value)
}
}
} # end of if grepl 'B'
if ((!grepl('A', df$Pattern[pos], ignore.case=TRUE))==TRUE){
# Only run this code if 'A' is NOT in string - issue lies in BAR_OUTPUT value
if ((grepl('C', df$Pattern[pos], ignore.case=TRUE))){
Condition_Pos<-as.numeric(df$Condition[pos])
if ((grepl('B', df$Pattern[pos], ignore.case=TRUE))){
# draw original bar -> avoids any issue with 'fill' and drawing incorrect height
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width)
point_1_percent_of_current_mean <- ((BAR_OUTPUT$data$Value[Condition_Pos]/100)*.1)
while((BAR_OUTPUT$data$Value[Condition_Pos])>=two_percent_of_largest_mean){
# this breaks while loop to prevent going below x-axis 0
if(((as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-(ggplot2_plot$data$Value[Condition_Pos]/100))<0){
break
}
BAR_OUTPUT$data$Value[Condition_Pos]<-(as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-two_percent_of_largest_mean
# This stops line very close to 0 on y-axis
if(((BAR_OUTPUT$data$Value[Condition_Pos])<((two_percent_of_largest_mean/100)*15))){
break
}
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width, fill='transparent')
}
} # end of sub grepl 'B'
# Code for right leaning diagonal 'C'
position_input_x<-as.numeric(df$Condition[pos])
position_input_y<-as.numeric(df$Condition[pos])
# half of input width
# when minused from centre of bar point on x-axis
# it gives value at start of bar on x-axis
# inverse true for end of bar width
half_input_width<-input_width/2
ten_perc_input_width<-((input_width/100)*10)
x_axis_min <- position_input_x-half_input_width
x_axis_max <- position_input_x+half_input_width
y_axis_max<- ggplot2_plot$data$Value[position_input_y]
# need to pull the max value from the example_plot the max boundries...
# or caluclate the
z_percent_of_current_mean<-(y_axis_max/100)*10
df_diag <- data.frame(
# start on x-axis-end on x-axis
x = c(x_axis_min,x_axis_min),
# start on y-axis-end on y-axis
y = c(y_axis_max,y_axis_max), Fill='Hope you\'re having a nice day.')
for(i in 1:19){
# run if 2nd x-position is less or equal to rightmost edge of bar
# minus 10% of total input width
if (df_diag$x[2]<(as.character(x_axis_max))){
# 1/10 of unit value in width field
df_diag$x[2]<-df_diag$x[2]+(ten_perc_input_width)
# subtract z percent from 1st y height
df_diag$y[1]<-df_diag$y[1]-(z_percent_of_current_mean)
# draw using current df_diag values
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when less than x_axis_max
# run this code to limit 2nd x-point from moving past rightmost edge of bar
if (df_diag$x[2]==as.character(x_axis_max)){
# drop height of 2nd y-position by z percentage
df_diag$y[2]<-df_diag$y[2]-(z_percent_of_current_mean)
if(df_diag$y[1]<=z_percent_of_current_mean){
df_diag$x[1]<-df_diag$x[1]+ten_perc_input_width
}
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when x_axis_max reached
} # end of for loop 1:19
} # end of grepl 'C'
if ((grepl('D', df$Pattern[pos], ignore.case=TRUE))){
Condition_Pos<-as.numeric(df$Condition[pos])
if ((grepl('B', df$Pattern[pos], ignore.case=TRUE))){
# draw original bar -> avoids any issue with 'fill' and drawing incorrect height
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width)
point_1_percent_of_current_mean <- ((BAR_OUTPUT$data$Value[Condition_Pos]/100)*.1)
while((BAR_OUTPUT$data$Value[Condition_Pos])>=two_percent_of_largest_mean){
# this breaks while loop to prevent going below x-axis 0
if(((as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-(ggplot2_plot$data$Value[Condition_Pos]/100))<0){
break
}
BAR_OUTPUT$data$Value[Condition_Pos]<-(as.numeric(BAR_OUTPUT$data$Value[Condition_Pos]))-two_percent_of_largest_mean
# This stops line very close to 0 on y-axis
if(((BAR_OUTPUT$data$Value[Condition_Pos])<((two_percent_of_largest_mean/100)*15))){
break
}
BAR_OUTPUT<-BAR_OUTPUT+geom_bar(data=BAR_OUTPUT$data[Condition_Pos,], position=position_dodge(input_position_dodge), stat="identity", colour=input_colour, size=input_size, width = ggplot2_plot$layers[[1]]$geom_params$width, fill='transparent')
}
} # end of sub grepl 'B'
# Code for left leaning diagonal 'D'
position_input_x<-as.numeric(df$Condition[pos])
position_input_y<-as.numeric(df$Condition[pos])
# half of input width
# when minused from centre of bar point on x-axis
# it gives value at start of bar on x-axis
# inverse true for end of bar width
half_input_width<-input_width/2
ten_perc_input_width<-((input_width/100)*10)
x_axis_min <- position_input_x-half_input_width
x_axis_max <- position_input_x+half_input_width
y_axis_max<- ggplot2_plot$data$Value[position_input_y]
# need to pull the max value from the example_plot the max boundries...
# or caluclate the
z_percent_of_current_mean<-(y_axis_max/100)*10
df_diag <- data.frame(
# start on x-axis-end on x-axis
x = c(x_axis_max,x_axis_max),
# start on y-axis-end on y-axis
y = c(y_axis_max,y_axis_max), Fill='Hope you\'re having a nice day.')
for(i in 1:19){
# run if 1st x-position is less or equal to leftmost edge of bar
# minus 10% of total input width
if (df_diag$x[2]>(as.character(x_axis_min))){
# 1/10 of unit value in width field
df_diag$x[2]<-df_diag$x[2]-(ten_perc_input_width)
# subtract z percent from 1st y height
df_diag$y[1]<-df_diag$y[1]-(z_percent_of_current_mean)
# draw using current df_diag values
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when less than x_axis_max
# run this code to limit 2nd x-point from moving past rightmost edge of bar
if (df_diag$x[2]==as.character(x_axis_min)){
# drop height of 2nd y-position by z percentage
df_diag$y[2]<-df_diag$y[2]-(z_percent_of_current_mean)
if(df_diag$y[1]<=z_percent_of_current_mean){
df_diag$x[1]<-df_diag$x[1]-ten_perc_input_width
}
BAR_OUTPUT<-BAR_OUTPUT+geom_path(data=df_diag, aes(x=x, y=y),colour = "black")
} # end of if statement when x_axis_max reached
} # end of for loop 1:19
} # end of grepl 'D'
} # end of no 'A' if statment
}
} # second loop
BAR_OUTPUT
}
# pattern letters and row numbers
# combine patterns by combining letters, for example: AB, ABC etc.
# A=vertical lines
# B=horizontal lines
# C=diagonal lines bottom-top
# D=diagonal lines top-bottom
# Numbers represent data index (row number) in dataframe
EggHatch_output<-EggHatch(example_plot, ('b=1, A=2, Ba=3, C=4, d=5, Dc=6, ABcD=7'))
EggHatch_output