While your graphical approach works great,
here's an approach that relies on the calculus definitions [since this is a calculus and beyond subforum]
and gives an interpretation.
(Screencaptured from a desmos calculation. Type it in yourself at
https://www.desmos.com/calculator .)
View attachment 278211
The Y_{avgSpeed} line is a little long:
Y_{avgSpeed}\left(T\right)=Y\left(0\right)+\left\{0\le T\le t_{1}:\ \left(s_{avg}T\cdot\operatorname{sign}\left(Y\left(1\right)-Y\left(0\right)\right)\right)\ ,t_{1}\le T\le4:\ \left(\left(Y\left(1\right)-Y\left(0\right)\right)+s_{avg}\left(T-t_{1}\right)\cdot\operatorname{sign}\left(Y\left(4\right)-Y\left(1\right)\right)\right)\right\}
(You can right-click on the equation, Show Math as \TeX commands, then copy to the clipboard, then paste into a Desmos cell.)
- Speed S is the magnitude of the [instantaneous] velocity V.
- Distance d traveled is the integral of the speed function over time.
- Average-speed s_{avg} is the time-weighted average of speed,
and is equal to the total distance divided by the total time.
The average-speed is
the constant speed of a traveler to travel the same total distance along the same path in space in the same time
as the given variable-velocity path.
This is, of course, different from the average-velocity,
which is the
the constant velocity of a traveler to travel the same total displacement between the endpoints in space in the same time
as the given variable-velocity path.