@@ -189,16 +189,16 @@ ggplot_gtable.ggplot_built <- function(data) {
189
189
position <- " none"
190
190
} else {
191
191
# these are a bad hack, since it modifies the contents of viewpoint directly...
192
- legend_width <- gtable_width(legend_box )
193
- legend_height <- gtable_height(legend_box )
194
192
195
- relative_height <- unitType(legend_height ) == " sum"
196
- relative_width <- unitType( legend_width ) == " sum "
197
- if ( relative_height ) {
198
- legend_height <- unit( 1 , " npc " )
193
+ if (any( unitType(legend_box $ widths ) == " sum" )) {
194
+ legend_width <- unit( 1 , " npc " )
195
+ } else {
196
+ legend_width <- gtable_width( legend_box )
199
197
}
200
- if (relative_width ) {
201
- legend_width <- unit(1 , " npc" )
198
+ if (any(unitType(legend_box $ heights ) == " sum" )) {
199
+ legend_height <- unit(1 , " npc" )
200
+ } else {
201
+ legend_height <- gtable_height(legend_box )
202
202
}
203
203
204
204
# Set the justification of the legend box
@@ -234,11 +234,11 @@ ggplot_gtable.ggplot_built <- function(data) {
234
234
width = legend_width
235
235
)
236
236
)
237
- if (! relative_height ) {
237
+ if (unitType( legend_height ) != " npc " ) {
238
238
legend_box <- gtable_add_rows(legend_box , unit(yjust , ' null' ))
239
239
legend_box <- gtable_add_rows(legend_box , unit(1 - yjust , ' null' ), 0 )
240
240
}
241
- if (! relative_width ) {
241
+ if (unitType( legend_width ) != " npc " ) {
242
242
legend_box <- gtable_add_cols(legend_box , unit(xjust , ' null' ), 0 )
243
243
legend_box <- gtable_add_cols(legend_box , unit(1 - xjust , ' null' ))
244
244
}
0 commit comments