<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def legend_aesthetics(self, layer, plot):
 """ Return the aesthetics that contribute to the legend Parameters layer : Layer Layer whose legend is to be drawn plot : ggplot Plot object Returns ------- matched : list List of the names of the aethetics that contribute to the legend. """

        l = layer
        legend_ae = set(self.key.columns) - {'label'}
        all_ae = (l.mapping.keys() |
                  (plot.mapping if l.inherit_aes else set()) |
                  l.stat.DEFAULT_AES.keys())
        geom_ae = l.geom.REQUIRED_AES | l.geom.DEFAULT_AES.keys()
        matched = all_ae & geom_ae & legend_ae
        matched = list(matched - set(l.geom.aes_params))
        return matched