How can I move the legend to the right to left alight with the plot above and move it down a little bit?
Also how can I move it to a specific position below the plot?
colors = ColorData[97] /@ Range[18];
list = {{"a"}, {"b", "c"}, {"d"}, {"e"}, {"f"}, {"g"}, {"h",
"k"}, {"l"}, {"m"}, {"n"}, {"p", "q",
"k"}, {"x"}, {"y"}, {"z"}, {"kh"}, {"xy"}, {"cy"}, {"cz"}};
linelegend =
LineLegend[{Opacity[opacity, Gray],
Directive[Red, Thickness[0.01], Dashed], White},
Style[#, 30, Bold, Black] & /@ {"mnk", "htk", "kn"},
"LegendItem" -> {"Square", Automatic, "Square"},
LegendMarkerSize -> 25];
opacity = 0.2;
Dynamic[Legended[
Row[{Plot[{x^2 - 1, 2 x - 3, 5 - 3 x, 5 x - 2 x^2}, {x, 0, 6},
GridLines -> Automatic,
PlotStyle ->
ReplacePart[
Directive[#, Thickness[0.005]] & /@
colors, {Except[Alternatives @@ n]} ->
Directive[Opacity[.01], Gray]],
Ticks -> Automatic,
Frame -> True,
Axes -> True,
PlotStyle -> Thickness[0.5],
PlotRange -> {{0, 6}, {0, 6}},
FrameStyle -> Directive[Black, Bold, 20],
GridLines -> Automatic,
GridLinesStyle -> LightGray,
Ticks -> Automatic,
TicksStyle -> Directive[Black, Bold, 20],
ImageSize -> 800,
Epilog -> {Directive[Red, Dashed, Thickness[0.003]],
Line[{{0, 1}, {1, 1}, {10, 10}}], Opacity[opacity, Gray],
Polygon[{{0, 1}, {1, 1}, {6, 6}, Scaled[{0, 1}, {6, 6}],
Scaled[{0, 1}, {0, 1}]}]}],
Spacer[10], linelegend}],
Placed[TogglerBar[Dynamic[n],
MapIndexed[#2[[1]] ->
ToString[
Framed[Style[#2[[1]], Black, Bold, 15],
ImageSize -> {45, 45}, Alignment -> Center,
Background -> LightBlue], StandardForm] <>
ToString[
Framed[Style[#, colors[[#2[[1]]]], Bold, 15],
ImageSize -> {230, 45}, Alignment -> Center,
Background -> White], StandardForm] &, list],
Appearance -> "Vertical" -> {Automatic, 3}], Below]]]