@@ -85,14 +85,14 @@ facet_grid_layout <- function(plots,
85
85
86
86
if (length(by ) == 2 ) {
87
87
88
- colsLabel <- subtitles [all.vars(by [[2 ]])]
88
+ colsLabel <- Filter(Negate( is.null ), subtitles [all.vars(by [[2 ]])])
89
89
rowsLabel <- list ()
90
90
91
91
} else {
92
92
# vars before tilde
93
- rowsLabel <- subtitles [all.vars(by [[2 ]])]
93
+ rowsLabel <- Filter(Negate( is.null ), subtitles [all.vars(by [[2 ]])])
94
94
# vars after tilde
95
- colsLabel <- subtitles [all.vars(by [[3 ]])]
95
+ colsLabel <- Filter(Negate( is.null ), subtitles [all.vars(by [[3 ]])])
96
96
}
97
97
98
98
} else {
@@ -176,17 +176,11 @@ facet_grid_layout <- function(plots,
176
176
177
177
}
178
178
}
179
-
180
-
181
179
} else {
182
180
183
181
for (i in seq(ncolsLabel )) {
184
182
for (j in seq(nrowsLabel )) {
185
183
id <- (i - 1 ) * nrowsLabel + j
186
- # plotid <- get_plot_id(layout_orders[id],
187
- # plot_names,
188
- # sep = sep)
189
- # plot_id <- c(plot_id, plotid)
190
184
new_names <- c(new_names , paste0(" x" , j , " y" , i ))
191
185
tkgrid(plots [[id ]],
192
186
row = (j - 1 ) * span + row_start_pos + title_pos , # leave space for labels
@@ -224,15 +218,16 @@ facet_grid_layout <- function(plots,
224
218
rep(fluid_colsLabel [[fluid_colsLabel_name ]], prod(lengths(colsLabel [1 : (j - 1 )])))
225
219
}
226
220
fluid_colsLabel [fluid_colsLabel_name ] <<- NULL
227
- extent <- prod(lengths(fluid_colsLabel ))
228
- columnspan <- extent * span
221
+ extend <- prod(lengths(fluid_colsLabel ))
222
+ columnspan <- extend * span
229
223
230
224
name <- column_names [j ]
231
225
label <- if (is.null(name )) {
232
226
col
233
227
} else {
234
228
if (grepl(" color" , name )) {
235
- l_colorName(col , error = FALSE )
229
+ l_colorName(col , error = FALSE ,
230
+ precise = TRUE )
236
231
} else {
237
232
col
238
233
}
@@ -244,7 +239,7 @@ facet_grid_layout <- function(plots,
244
239
tkcolname <- as.character(tcltk :: tcl(' label' ,
245
240
as.character(l_subwin(parent ,
246
241
paste0(' columnlabel-' , columnLabelLocation , ' -' ,
247
- ' x' , j , ' y' , i , ' extent ' , extent ))),
242
+ ' x' , j , ' y' , i , ' extend ' , extend ))),
248
243
text = text ,
249
244
bg = labelBackground ,
250
245
fg = labelForeground ,
@@ -296,8 +291,8 @@ facet_grid_layout <- function(plots,
296
291
297
292
name <- row_names [i ]
298
293
299
- extent <- prod(lengths(fluid_rowsLabel ))
300
- rowspan <- extent * span
294
+ extend <- prod(lengths(fluid_rowsLabel ))
295
+ rowspan <- extend * span
301
296
for (j in seq(length(row ))) {
302
297
# row index
303
298
label <- row [j ]
@@ -307,7 +302,8 @@ facet_grid_layout <- function(plots,
307
302
ifelse(
308
303
grepl(" color" , name ),
309
304
{
310
- l_colorName(label , error = FALSE )
305
+ l_colorName(label , error = FALSE ,
306
+ precise = TRUE )
311
307
},
312
308
{
313
309
label
@@ -316,7 +312,7 @@ facet_grid_layout <- function(plots,
316
312
tkrowname <- as.character(tcltk :: tcl(' label' ,
317
313
as.character(l_subwin(parent ,
318
314
paste0(' rowlabel-' , rowLabelLocation , ' -' ,
319
- ' x' , j , ' y' , i , ' extent ' , extent ))),
315
+ ' x' , j , ' y' , i , ' extend ' , extend ))),
320
316
text = paste(paste0(" " , strsplit(text , " " )[[1 ]], " " ), collapse = " \n " ),
321
317
bg = labelBackground ,
322
318
fg = labelForeground ,
@@ -325,14 +321,14 @@ facet_grid_layout <- function(plots,
325
321
if (rowLabelLocation == " right" )
326
322
tkgrid(tkrowname ,
327
323
row = (j - 1 ) * rowspan + row_start_pos + title_pos ,
328
- column = - (i - 1 ) + ncolsLabel * span + len_colsLabel + ylabel_pos ,
324
+ column = - (i - len_rowsLabel ) + ncolsLabel * span + len_colsLabel + ylabel_pos ,
329
325
rowspan = rowspan ,
330
326
columnspan = 1 ,
331
327
sticky = " nesw" )
332
328
else
333
329
tkgrid(tkrowname ,
334
330
row = (j - 1 ) * rowspan + row_start_pos + title_pos ,
335
- column = (i - 1 )+ ylabel_pos ,
331
+ column = (i - 1 ) + ylabel_pos ,
336
332
rowspan = rowspan ,
337
333
columnspan = 1 ,
338
334
sticky = " nesw" )
@@ -475,7 +471,7 @@ facet_wrap_layout <- function(plots,
475
471
nrow = NULL ,
476
472
ncol = NULL ,
477
473
labelLocation = " top" ,
478
- byrow = FALSE ,
474
+ byrow = TRUE ,
479
475
swapAxes = FALSE ,
480
476
labelBackground = l_getOption(" facetLabelBackground" ),
481
477
labelForeground = l_getOption(" foreground" ),
@@ -500,8 +496,13 @@ facet_wrap_layout <- function(plots,
500
496
501
497
if (is.null(nrow ) && is.null(ncol )) {
502
498
nm <- grDevices :: n2mfrow(N )
503
- nrow <- nm [2 ]
504
- ncol <- nm [1 ]
499
+ if (byrow ) {
500
+ nrow <- nm [2 ]
501
+ ncol <- nm [1 ]
502
+ } else {
503
+ nrow <- nm [1 ]
504
+ ncol <- nm [2 ]
505
+ }
505
506
}
506
507
507
508
# ** respect to the number of columns **
@@ -570,16 +571,18 @@ facet_wrap_layout <- function(plots,
570
571
split <- paste0(" [" , sep , " ]" )
571
572
if (byrow ) {
572
573
573
- for (j in seq(ncol )) {
574
- for (i in seq(nrow )) {
574
+ for (i in seq(nrow )) {
575
+ for (j in seq(ncol )) {
575
576
576
- plotid <- (j - 1 ) * nrow + i
577
+ plotid <- (i - 1 ) * ncol + j
577
578
if (plotid > N ) break ()
578
579
579
580
new_names <- c(new_names , paste0(" x" , i , " y" , j ))
580
581
581
582
label <- strsplit(plot_names [plotid ], split = split )[[1 ]]
582
- stopifnot(length(label ) == label_span )
583
+ stopifnot(
584
+ length(label ) == label_span
585
+ )
583
586
584
587
if (labelLocation == " top" ) {
585
588
# pack plots
@@ -589,6 +592,7 @@ facet_wrap_layout <- function(plots,
589
592
rowspan = plots_span ,
590
593
columnspan = plots_span ,
591
594
sticky = " nesw" )
595
+
592
596
# pack labels
593
597
lapply(seq(length(label )),
594
598
function (k ) {
@@ -598,10 +602,11 @@ facet_wrap_layout <- function(plots,
598
602
text <- if (is.null(name )) {
599
603
l
600
604
} else {
605
+
601
606
ifelse(
602
607
grepl(" color" , name ), {
603
- l_colorName(l , error = FALSE )
604
-
608
+ l_colorName(l , error = FALSE ,
609
+ precise = TRUE )
605
610
}, {
606
611
l
607
612
})
@@ -617,7 +622,7 @@ facet_wrap_layout <- function(plots,
617
622
relief = labelRelief ))
618
623
tkgrid(tklabel ,
619
624
row = (i - 1 ) * span + (k - 1 ) + title_pos ,
620
- column = (j - 1 ) * plots_span + ylabel_pos ,
625
+ column = (j - 1 ) * plots_span + ylabel_pos ,
621
626
rowspan = 1 ,
622
627
columnspan = plots_span ,
623
628
sticky = " nesw" )
@@ -644,7 +649,8 @@ facet_wrap_layout <- function(plots,
644
649
645
650
ifelse(
646
651
grepl(" color" , name ), {
647
- l_colorName(l , error = FALSE )
652
+ l_colorName(l , error = FALSE ,
653
+ precise = TRUE )
648
654
}, {
649
655
l
650
656
})
@@ -673,18 +679,16 @@ facet_wrap_layout <- function(plots,
673
679
674
680
} else {
675
681
676
- for (i in seq(nrow )) {
677
- for (j in seq(ncol )) {
682
+ for (j in seq(ncol )) {
683
+ for (i in seq(nrow )) {
678
684
679
- plotid <- (i - 1 ) * ncol + j
685
+ plotid <- (j - 1 ) * nrow + i
680
686
if (plotid > N ) break ()
681
687
682
688
new_names <- c(new_names , paste0(" x" , i , " y" , j ))
683
689
684
690
label <- strsplit(plot_names [plotid ], split = split )[[1 ]]
685
- stopifnot(
686
- length(label ) == label_span
687
- )
691
+ stopifnot(length(label ) == label_span )
688
692
689
693
if (labelLocation == " top" ) {
690
694
# pack plots
@@ -694,7 +698,6 @@ facet_wrap_layout <- function(plots,
694
698
rowspan = plots_span ,
695
699
columnspan = plots_span ,
696
700
sticky = " nesw" )
697
-
698
701
# pack labels
699
702
lapply(seq(length(label )),
700
703
function (k ) {
@@ -704,10 +707,11 @@ facet_wrap_layout <- function(plots,
704
707
text <- if (is.null(name )) {
705
708
l
706
709
} else {
707
-
708
710
ifelse(
709
711
grepl(" color" , name ), {
710
- l_colorName(l , error = FALSE )
712
+ l_colorName(l , error = FALSE ,
713
+ precise = TRUE )
714
+
711
715
}, {
712
716
l
713
717
})
@@ -723,7 +727,7 @@ facet_wrap_layout <- function(plots,
723
727
relief = labelRelief ))
724
728
tkgrid(tklabel ,
725
729
row = (i - 1 ) * span + (k - 1 ) + title_pos ,
726
- column = (j - 1 ) * plots_span + ylabel_pos ,
730
+ column = (j - 1 ) * plots_span + ylabel_pos ,
727
731
rowspan = 1 ,
728
732
columnspan = plots_span ,
729
733
sticky = " nesw" )
@@ -750,7 +754,8 @@ facet_wrap_layout <- function(plots,
750
754
751
755
ifelse(
752
756
grepl(" color" , name ), {
753
- l_colorName(l , error = FALSE )
757
+ l_colorName(l , error = FALSE ,
758
+ precise = TRUE )
754
759
}, {
755
760
l
756
761
})
@@ -776,7 +781,6 @@ facet_wrap_layout <- function(plots,
776
781
} else stop(" Unknown 'labelLocation'. It can only be one of 'top' or 'bottom'." )
777
782
}
778
783
}
779
-
780
784
}
781
785
782
786
# pack title
@@ -907,7 +911,8 @@ facet_separate_layout <- function(plots,
907
911
function (name ) {
908
912
909
913
subtitle <- l_colorName(strsplit(name , split = split )[[1 ]],
910
- error = FALSE )
914
+ error = FALSE ,
915
+ precise = TRUE )
911
916
paste(c(title , subtitle ), collapse = " \n " )
912
917
}, character (1 ))
913
918
}
0 commit comments