'Some types of geoms (layer) need to be prepped before calling the plot
function on them. This function performs those perperations and then
returns a dictionary of **kwargs for the layer.plot function to use.'

def _prep_layer_for_plotting(self, layer, facetgroup):

    if (layer.__class__.__name__ == u'geom_bar'):
        mask = True
        df = layer.setup_data(self.data, self._aes, facets=self.facets)
        if (df is None):
            return False
        if self.facets:
            facet_filter = facetgroup[self.facets.facet_cols].iloc[0].to_dict()
            for (k, v) in facet_filter.items():
                mask = (mask & (df[k] == v))
            df = df[mask]
        if (u'fill' in self._aes):
            fillcol_raw = self._aes[u'fill'][:(-5)]
            fillcol = self._aes[u'fill']
            fill_levels = self.data[[fillcol_raw, fillcol]].sort(fillcol_raw)[fillcol].unique()
        else:
            fill_levels = None
        return dict(x_levels=self.data[self._aes[u'x']].unique(), fill_levels=fill_levels, lookups=df)
    elif (layer.__class__.__name__ in (u'geom_boxplot', u'geom_violin', u'geom_errorbar')):
        x_levels = list(pd.Series(self.data[self._aes[u'x']].unique()).sort_values())
        return dict(x_levels=x_levels)
    else:
        return dict()
