Adding the Mean
The mean shows the average within a dataset.
We'll cover the following
We are going to add a bonus feature to our histogram. The reader may want to know what the mean is in our dataset. The mean is the average value in our dataset. Averages give readers a good idea of what to expect from our data.
We will add the average value by drawing a line in our histogram. The line will be positioned where the average is. In addition, the line will animate into a different location whenever the metric changes. Let’s get started.
Creating the line
In the script section, we are going to create a selection for the line. There will only be one line in our image. It would not be a bad idea to draw it before we draw the histogram. We are going to draw the line right before the histogram()
function.
Create a variable called meanLine
. Its value will be the ctr.append()
function.
Get hands-on with 1400+ tech skills courses.