@@ -139,20 +139,27 @@ labelGrob <- function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"),
139
139
descent <- font_descent(
140
140
text.gp $ fontfamily , text.gp $ fontface , text.gp $ fontsize , text.gp $ cex
141
141
)
142
+ # To balance labels, we ensure the top includes at least the descent height
143
+ # and subtract the descent height from the bottom padding
144
+ padding [1 ] <- unit.pmax(padding [1 ], descent )
145
+ padding [3 ] <- unit.pmax(padding [3 ] - descent , unit(0 , " pt" ))
146
+
142
147
hjust <- resolveHJust(just , NULL )
143
148
vjust <- resolveVJust(just , NULL )
144
149
145
150
text <- titleGrob(
146
- label = label , hjust = hjust , vjust = vjust , x = x , y = y ,
151
+ label = label , hjust = hjust , vjust = vjust , x = x ,
152
+ y = y + (1 - vjust ) * descent ,
147
153
margin = padding , margin_x = TRUE , margin_y = TRUE ,
148
154
gp = text.gp
149
155
)
150
156
157
+ height <- heightDetails(text )
151
158
box <- roundrectGrob(
152
- x = x , y = y - ( 1 - vjust ) * descent ,
159
+ x = x , y = y + ( 0.5 - vjust ) * height ,
153
160
width = widthDetails(text ),
154
- height = heightDetails( text ) ,
155
- just = c(hjust , vjust ),
161
+ height = height ,
162
+ just = c(hjust , 0.5 ),
156
163
r = r , gp = rect.gp , name = " box"
157
164
)
158
165
0 commit comments