>>> gg = ggplot(diamonds, aes(x='cut', y='clarity'))
        >>> gg = gg + stat_sum(aes(group='cut'))
        >>> gg + scale_size(range=(3, 25))

        Note the different height sizes for the entries

def _set_defaults(self):
        guide._set_defaults(self)

        nbreak = len(self.key)

        # rows and columns
        if self.nrow is not None and self.ncol is not None:
            if guide.nrow * guide.ncol < nbreak:
                raise PlotnineError(
                    "nrow x ncol need to be larger",
                    "than the number of breaks")

        if self.nrow is None and self.ncol is None:
            if self.direction == 'horizontal':
                self.nrow = int(np.ceil(nbreak/5))
            else:
                self.ncol = int(np.ceil(nbreak/20))

        self.nrow = self.nrow or int(np.ceil(nbreak/self.ncol))
        self.ncol = self.ncol or int(np.ceil(nbreak/self.nrow))

        # key width and key height for each legend entry
        #
        # Take a peak into data['size'] to make sure the
        # legend dimensions are big enough
        """
        >>> gg = ggplot(diamonds, aes(x='cut', y='clarity'))
        >>> gg = gg + stat_sum(aes(group='cut'))
        >>> gg + scale_size(range=(3, 25))

        Note the different height sizes for the entries
        """

        # FIXME: This should be in the geom instead of having
        # special case conditional branches
        def determine_side_length(initial_size):
            default_pad = initial_size * 0.5
            # default_pad = 0
            size = np.ones(nbreak) * initial_size
            for i in range(nbreak):
                for gl in self.glayers:
                    _size = 0
                    pad = default_pad
                    # Full size of object to appear in the
                    # legend key
                    with suppress(IndexError):
                        if 'size' in gl.data:
                            _size = gl.data['size'].iloc[i] * SIZE_FACTOR
                            if 'stroke' in gl.data:
                                _size += (2 * gl.data['stroke'].iloc[i] *
                                          SIZE_FACTOR)

                        # special case, color does not apply to
                        # border/linewidth
                        if issubclass(gl.geom, geom_text):
                            pad = 0
                            if _size < initial_size:
                                continue

                        try:
                            # color(edgecolor) affects size(linewidth)
                            # When the edge is not visible, we should
                            # not expand the size of the keys
                            if gl.data['color'].iloc[i] is not None:
                                size[i] = np.max([_size+pad, size[i]])
                        except KeyError:
                            break

            return size

        # keysize
        if self.keywidth is None:
            width = determine_side_length(
                self._default('legend_key_width', 18))
            if self.direction == 'vertical':
                width[:] = width.max()
            self._keywidth = width
        else:
            self._keywidth = [self.keywidth]*nbreak

        if self.keyheight is None:
            height = determine_side_length(
                self._default('legend_key_height', 18))
            if self.direction == 'horizontal':
                height[:] = height.max()
            self._keyheight = height
        else:
            self._keyheight = [self.keyheight]*nbreak