@@ -535,21 +535,24 @@ gg2list <- function(p, width = NULL, height = NULL,
535
535
536
536
# panel margins must be computed before panel/axis loops
537
537
# (in order to use get_domains())
538
- panelMarginX <- unitConvert(
538
+ panelMarginL <- 0.5 * unitConvert(
539
539
theme [[" panel.spacing.x" ]] %|| % theme [[" panel.spacing" ]],
540
540
" npc" , " width"
541
541
)
542
- panelMarginY <- unitConvert(
542
+ panelMarginR <- panelMarginL
543
+ panelMarginT <- 0.5 * unitConvert(
543
544
theme [[" panel.spacing.y" ]] %|| % theme [[" panel.spacing" ]],
544
545
" npc" , " height"
545
546
)
547
+ panelMarginB <- panelMarginT
546
548
# space for _interior_ facet strips
547
549
if (inherits(plot $ facet , " FacetWrap" )) {
548
550
stripSize <- unitConvert(
549
551
theme [[" strip.text.x" ]] %|| % theme [[" strip.text" ]],
550
552
" npc" , " height"
551
553
)
552
- panelMarginY <- panelMarginY + stripSize
554
+ # FIXME add to MarginB if strip position is below?
555
+ panelMarginT <- panelMarginT + stripSize
553
556
# space for ticks/text in free scales
554
557
if (plot $ facet $ params $ free $ x ) {
555
558
axisTicksX <- unitConvert(
@@ -560,7 +563,8 @@ gg2list <- function(p, width = NULL, height = NULL,
560
563
axisTextX <- theme [[" axis.text.x" ]] %|| % theme [[" axis.text" ]]
561
564
labz <- unlist(lapply(layout $ panel_params , " [[" , " x.labels" ))
562
565
lab <- labz [which.max(nchar(labz ))]
563
- panelMarginY <- panelMarginY + axisTicksX +
566
+ # FIXME add to MarginT if axis position is above?
567
+ panelMarginB <- panelMarginB + axisTicksX +
564
568
bbox(lab , axisTextX $ angle , unitConvert(axisTextX , " npc" , " height" ))[[" height" ]]
565
569
}
566
570
if (plot $ facet $ params $ free $ y ) {
@@ -572,14 +576,12 @@ gg2list <- function(p, width = NULL, height = NULL,
572
576
axisTextY <- theme [[" axis.text.y" ]] %|| % theme [[" axis.text" ]]
573
577
labz <- unlist(lapply(layout $ panel_params , " [[" , " y.labels" ))
574
578
lab <- labz [which.max(nchar(labz ))]
575
- panelMarginX <- panelMarginX + axisTicksY +
579
+ # FIXME add to MarginR if axis position is on the right?
580
+ panelMarginL <- panelMarginL + axisTicksY +
576
581
bbox(lab , axisTextY $ angle , unitConvert(axisTextY , " npc" , " width" ))[[" width" ]]
577
582
}
578
583
}
579
- margins <- c(
580
- rep(panelMarginX , 2 ),
581
- rep(panelMarginY , 2 )
582
- )
584
+ margins <- c(panelMarginL , panelMarginR , panelMarginT , panelMarginB )
583
585
doms <- get_domains(nPanels , nRows , margins )
584
586
585
587
for (i in seq_len(nPanels )) {
0 commit comments