@@ -420,7 +420,7 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
420
420
gglayout $ annotations ,
421
421
make_label(
422
422
faced(axisTitleText , axisTitle $ face ), x , y , el = axisTitle ,
423
- xanchor = " center" , yanchor = " middle"
423
+ xanchor = " center" , yanchor = " middle" , annotationType = " axis "
424
424
)
425
425
)
426
426
}
@@ -432,36 +432,52 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
432
432
ydom <- gglayout [[lay [, " yaxis" ]]]$ domain
433
433
border <- make_panel_border(xdom , ydom , theme )
434
434
gglayout $ shapes <- c(gglayout $ shapes , border )
435
-
436
435
# facet strips -> plotly annotations
436
+ if (has_facet(p )) {
437
+ col_vars <- ifelse(inherits(p $ facet , " wrap" ), " facets" , " cols" )
438
+ col_txt <- paste(
439
+ p $ facet $ labeller(lay [names(p $ facet [[col_vars ]])]), collapse = " , "
440
+ )
441
+ if (nchar(col_txt ) > 0 ) {
442
+ col_lab <- make_label(
443
+ col_txt , x = mean(xdom ), y = max(ydom ),
444
+ el = theme [[" strip.text.x" ]] %|| % theme [[" strip.text" ]],
445
+ xanchor = " center" , yanchor = " bottom"
446
+ )
447
+ gglayout $ annotations <- c(gglayout $ annotations , col_lab )
448
+ strip <- make_strip_rect(xdom , ydom , theme , " top" )
449
+ gglayout $ shapes <- c(gglayout $ shapes , strip )
450
+ }
451
+ row_txt <- paste(
452
+ p $ facet $ labeller(lay [names(p $ facet $ rows )]), collapse = " , "
453
+ )
454
+ if (nchar(row_txt ) > 0 ) {
455
+ row_lab <- make_label(
456
+ row_txt , x = max(xdom ), y = mean(ydom ),
457
+ el = theme [[" strip.text.y" ]] %|| % theme [[" strip.text" ]],
458
+ xanchor = " left" , yanchor = " middle"
459
+ )
460
+ gglayout $ annotations <- c(gglayout $ annotations , row_lab )
461
+ strip <- make_strip_rect(xdom , ydom , theme , " right" )
462
+ gglayout $ shapes <- c(gglayout $ shapes , strip )
463
+ }
464
+
465
+
466
+
467
+ }
468
+
469
+
437
470
if (! is_blank(theme [[" strip.text.x" ]]) &&
438
471
(inherits(p $ facet , " wrap" ) || inherits(p $ facet , " grid" ) && lay $ ROW == 1 )) {
439
472
vars <- ifelse(inherits(p $ facet , " wrap" ), " facets" , " cols" )
440
- txt <- paste(
441
- p $ facet $ labeller(lay [names(p $ facet [[vars ]])]), collapse = " , "
442
- )
443
- lab <- make_label(
444
- txt , x = mean(xdom ), y = max(ydom ),
445
- el = theme [[" strip.text.x" ]] %|| % theme [[" strip.text" ]],
446
- xanchor = " center" , yanchor = " bottom"
447
- )
448
- gglayout $ annotations <- c(gglayout $ annotations , lab )
449
- strip <- make_strip_rect(xdom , ydom , theme , " top" )
450
- gglayout $ shapes <- c(gglayout $ shapes , strip )
473
+
474
+
475
+
451
476
}
452
477
if (inherits(p $ facet , " grid" ) && lay $ COL == nCols && nRows > 1 &&
453
478
! is_blank(theme [[" strip.text.y" ]])) {
454
- txt <- paste(
455
- p $ facet $ labeller(lay [names(p $ facet $ rows )]), collapse = " , "
456
- )
457
- lab <- make_label(
458
- txt , x = max(xdom ), y = mean(ydom ),
459
- el = theme [[" strip.text.y" ]] %|| % theme [[" strip.text" ]],
460
- xanchor = " left" , yanchor = " middle"
461
- )
462
- gglayout $ annotations <- c(gglayout $ annotations , lab )
463
- strip <- make_strip_rect(xdom , ydom , theme , " right" )
464
- gglayout $ shapes <- c(gglayout $ shapes , strip )
479
+
480
+
465
481
}
466
482
467
483
} # end of panel loop
0 commit comments