Creating a single function to plot multiple things

I want to be able to pass the same data and change the type of chart. Is this the best way to be generic about it?

How might I change this function to do what I want it to do?

function createPlot(plotSettings, plotConfig, data) {
  plotConfig = {
    grid: plotConfig.grid || true,
    width: plotConfig.width || 800,
    height: plotConfig.height || 400,
    marginTop: plotConfig.marginTop || 20,
    marginRight: plotConfig.marginRight || 20,
    marginBottom: plotConfig.marginBottom || 40,
    marginLeft: plotConfig.marginLeft || 40,
    x: plotConfig.x || {
      type: "band",
      tickFormat: d3.timeFormat("%b %d"),
    },
    y: plotConfig.y || {
      tickFormat: d3.format("d"),
    },
  }

  let x = plotSettings.x || "date";
  let y = plotSettings.y || "value";

  console.log(data);
  let plotType = plotSettings.type || "line";
  if (plotType === "line") {
    plotConfig["marks"] = [
      Plot.lineY(data, {x: x, y: y})
    ]
  } else if (plotType === "bar") {
    plotConfig["marks"] = [
      Plot.barY(data, {x: x, y: y})
    ]
  } else if (plotType === "stackedBar") {
    plotConfig["marks"] = [
      Plot.barY(data, {x: x, y: y, fill: "color", stroke: "color"})
    ]
    plotConfig["color"] = {
      scheme: "Greys",
      type: "categorical",
      legend: "ramp",
      label: "Test Status",
      domain: ["timedout", "finished"]
    }
  }

  let plot;
  plot = Plot.plot(plotConfig);
  return plot;
}