code: def _get_marginal_layers(
      marginal, binwidth2d, bins2d, color, color_by, show_legend
  ):
      marginal_color = (
          None if color_by is not None else (color or _COLOR_DEF)
      )
  
      def bin_param_to_1d(param2d, side):
          if param2d is None:
              return None
          else:
              if side in ["t", "b"]:
                  return param2d[0]
              else:
                  return param2d[1]
  
      def _get_marginal_layer(geom_kind, side, size):
          if geom_kind in ["dens", "density"]:
              layer = geom_area(
                  stat="density",
                  position="identity",
                  color=marginal_color,
                  fill=marginal_color,
                  alpha=_MARGINAL_ALPHA,
                  show_legend=show_legend,
              )
          elif geom_kind in ["hist", "histogram"]:
              binwidth = bin_param_to_1d(binwidth2d, side)
              bins = bin_param_to_1d(bins2d, side)
              layer = geom_histogram(
                  bins=bins,
                  binwidth=binwidth,
                  color=marginal_color,
                  fill=marginal_color,
                  alpha=_MARGINAL_ALPHA,
                  show_legend=show_legend,
              )
          elif geom_kind in ["box", "boxplot"]:
              layer = geom_boxplot(
                  color=marginal_color,
                  fill=marginal_color,
                  alpha=_MARGINAL_ALPHA,
                  show_legend=show_legend,
              )
          else:
              raise Exception("Unknown geom '{0}'".format(geom_kind))
  
          return ggmarginal(side, size=size, layer=layer)
  
      marginals = []
      for layer_description in filter(bool, marginal.split(",")):
          params = layer_description.strip().split(":")
          geom_kind, sides = params[0].strip(), params[1].strip()
          size = float(params[2].strip()) if len(params) > 2 else None
          for side in sides:
              layer = _get_marginal_layer(geom_kind, side, size)
              if isinstance(layer, LayerSpec):
                  marginals.append(layer)
              elif isinstance(layer, FeatureSpecArray):
                  for sublayer in layer.elements():
                      marginals.append(sublayer)
              else:
                  raise TypeError(
                      "Invalid 'layer' type: {}".format(type(layer))
                  )
  
      return marginals
  
imports: from ..plot.core import LayerSpec, FeatureSpecArray, aes
  from ..plot.geom import *
  from ..plot.marginal_layer import ggmarginal
label_desc: Use image node_id 3 for calling a global function with example usage: _get_marginal_layers(marginal, binwidth2d, bins2d, color, color_by, show_legend) and returns: marginals, ggmarginal, None, param2d, param2d