code: def get_scale(self, gg):
          
          # This method does some introspection to save users from
          # scale mismatch error. This could happen when the
          # aesthetic is mapped to a categorical but the limits
          # are not provided in categorical form. We only handle
          # the case where the mapping uses an expression to
          # conver to categorical e.g `aes(color='factor(cyl)')`.
          # However if `'cyl'` column is a categorical and the
          # mapping is `aes(color='cyl')`, that will result in
          # an error. If later case proves common enough then we
          # could inspect the data and be clever based on that too!!
          ae = self.aesthetic
          series = self.limits_series
          ae_values = []
  
          # Look through all the mappings for this aesthetic,
          # if we detect any factor stuff then we convert the
          # limits data to categorical so that the right scale
          # can be choosen. This should take care of the most
          # common use cases.
          for layer in gg.layers:
              with suppress(KeyError):
                  value = layer.mapping[ae]
                  if isinstance(value, str):
                      ae_values.append(value)
  
          for value in ae_values:
              if ('factor(' in value or
                      'Categorical(' in value):
                  series = pd.Categorical(self.limits_series)
                  break
          return make_scale(self.aesthetic,
                            series,
                            limits=self.limits,
                            trans=self.trans)
docs: Create a scale