Changing the x and y axis labels

I created a boxplot through ObservableHQ but would like to know how I can edit the x and y-axis labels. Here is the code I’m using:

Plot.plot({
            x: {
                grid: true,
                inset: 6,
            },
            marks: [
                Plot.boxX(data, {
                    x,
                    y: 'instance',
                    fill: '#0d6efd',
                    strokeWidth: 3,
                }),
                Plot.boxX(userData, {
                    x,
                    y: 'instance',
                    fill: 'yellow',
                    strokeWidth: 3,
                }),
            ],
        })
1 Like

You can use the x and y options to Plot.plot like so:

box_plot = Plot.plot({
  // Change the x-axis label from body_mass_g to the nicer "Body mass →"
  x: { label: "Body mass →" },

  // Also change the y-axis and, and place it at the top as well.
  y: { label: "Species", labelAnchor: "top" },
  width: 800,
  height: 300,
  marks: [Plot.boxX(penguins, { x: "body_mass_g", y: "species" })]
})

Note that the GitHub page is an excellent reference for this sort of thing.

2 Likes

Thank you for this. I’ve been trying to look for documentation all day. I’ll know where to look now going forwards when it comes to options.

1 Like