The line
every axis legend/.append style={ at={(0.05,0.95)}, anchor=north west,legend columns = 1
in the pgfplotset{} should do it!
The anchor tells the legend which corner it wants to give coordinates to, and the coordinates in "append style ={ at = {(x,y)} }" tells that corner where you want it to go.
I usually just fiddle around with numbers until I like what I see, but you can use the general rule that between 0 and 1 is inside the plot and more than 1 is outside. So for example, if you want it just to the right of where it currently is, but outside the plot, you might use:
\begin{tikzpicture}
\pgfplotsset{
every axis legend/.append style={ at={(1.05,0.95)}, anchor=north west,legend columns = 1}}
\begin{axis}
... rest of plotting ...
\end{axis}
\end{tikzpicture}