Initialization

(* https://mathematica.stackexchange.com/questions/54545/is-it-possible-to-define-a-new-plottheme *)
Begin["System`PlotThemeDump`"];
Themes`ThemeRules;(*preload Theme system*)

resolvePlotTheme["myTheme",def:_String]:=
Themes`SetWeight[Join[
{ImageSize->Large},
{LabelStyle->Directive[FontFamily->"Libertinus Serif",FontSize->22]},
{TicksStyle->Directive[FontSize->18]},
{PlotStyle->Directive[PointSize[0.015]]}
]
,$ComponentWeight];

End[];

Main algorithm

x[μ_]:=data[[μ]];

(* Centroid is the average of all cluster points *)
centroid[C_]:=(1/(Length[C]))(∑_(i=1)^(Length[C]))C[[i]];

(* Variance is the quadratic euclidean distance from all data points to their centroids *)
variance[t_]:=(∑_(i=1)^2)(∑_(k=1)^(Length[(Subscript[C, i])[t]]))((Norm[(Subscript[C, i])[t][[k]]-centroid[(Subscript[C, i])[t]]])^2);
variance[C1_,C2_]:=(∑_(k=1)^(Length[C1]))((Norm[C1[[k]]-centroid[C1]])^2)+(∑_(k=1)^(Length[C2]))((Norm[C2[[k]]-centroid[C2]])^2);

(* Diference in variance when the point x is moved from the source cluster to the target cluster *)
f[x_,Csource_,Ctarget_]:=((Length[Csource])/(Length[Csource]-1))((Norm[x-centroid[Csource]])^2)-((Length[Ctarget])/(Length[Ctarget]+1))((Norm[x-centroid[Ctarget]])^2);

plotCluster[t_]:=Module[{xPos,tCentroids,tFraction,pointColor,varianceLines,C1Temp,C2Temp,var1Temp,var2Temp,centroid1,centroid2,centroidsTemp,colorC1=,colorC2=,title,varianceStepText,checkNmin,centroidMarkers},
If[Length[data]≤2||Length[(Subscript[C, 1])[0]]<(Subscript[n, min])||Length[(Subscript[C, 2])[0]]<(Subscript[n, min]),Return[]];

(* Returns true, if an exchange is possible (cluster of x has enough points) *)
checkNmin[]:=Module[{},
MemberQ[(Subscript[C, 1])[⌊t⌋],x[xPos]]&&Length[(Subscript[C, 1])[⌊t⌋]]>(Subscript[n, min])||MemberQ[(Subscript[C, 2])[⌊t⌋],x[xPos]]&&Length[(Subscript[C, 2])[⌊t⌋]]>(Subscript[n, min])
];

xPos=({{\[Piecewise], ({{Mod[⌈t⌉-1,Length[data]]+1, ⌈t⌉≠0}, {0, True}})}});
tFraction=FractionalPart[t];
tCentroids=⌊t⌋;
pointColor=({{\[Piecewise], ({{({{\[Piecewise], ({{colorC1, MemberQ[(Subscript[C, 1])[⌊t⌋],x[xPos]]}, {colorC2, MemberQ[(Subscript[C, 2])[⌊t⌋],x[xPos]]}, {None, True}})}}), tFraction==0.25}, {({{\[Piecewise], ({{colorC2, MemberQ[(Subscript[C, 1])[⌊t⌋],x[xPos]]}, {colorC1, MemberQ[(Subscript[C, 2])[⌊t⌋],x[xPos]]}, {None, True}})}}), checkNmin[]&&(tFraction==0.5||tFraction==0.75)}, {({{\[Piecewise], ({{colorC1, MemberQ[(Subscript[C, 1])[⌈t⌉],x[xPos]]}, {colorC2, MemberQ[(Subscript[C, 2])[⌈t⌉],x[xPos]]}, {None, True}})}}), True}})}});
centroidMarkers={{"◆",16},{"◆",16}};

(* Current centroid *)
centroid1=centroid[(Subscript[C, 1])[tCentroids]];
centroid2=centroid[(Subscript[C, 2])[tCentroids]];

centroidsTemp={};
varianceLines={};
varianceStepText={};
If[tFraction==0.75&&checkNmin[],
var1Temp=0;
var2Temp=0;

(* Temporally shift the current point to the cluster where it normally does not belong to *)
C1Temp=({{\[Piecewise], ({{Complement[(Subscript[C, 1])[⌊t⌋],{x[xPos]}], MemberQ[(Subscript[C, 1])[⌊t⌋],x[xPos]]}, {Union[(Subscript[C, 1])[⌊t⌋],{x[xPos]}], MemberQ[(Subscript[C, 2])[⌊t⌋],x[xPos]]}})}});
C2Temp=({{\[Piecewise], ({{Complement[(Subscript[C, 2])[⌊t⌋],{x[xPos]}], MemberQ[(Subscript[C, 2])[⌊t⌋],x[xPos]]}, {Union[(Subscript[C, 2])[⌊t⌋],{x[xPos]}], MemberQ[(Subscript[C, 1])[⌊t⌋],x[xPos]]}})}});

(* Line objects (graphics) *)
(AppendTo[varianceLines,
Graphics[{
colorC1,
Opacity[0.5],
Line[{centroid[C1Temp],#}]
}]
])&/@C1Temp;
(AppendTo[varianceLines,
Graphics[{
colorC2,
Opacity[0.5],
Line[{centroid[C2Temp],#}]
}]
])&/@C2Temp;

(* Line lengths *)
(var1Temp+=((ArcLength[Line[{centroid[C1Temp],#}]])^2))&/@C1Temp;
(var2Temp+=((ArcLength[Line[{centroid[C2Temp],#}]])^2))&/@C2Temp;

centroidsTemp=ListPlot[{{centroid[(Subscript[C, 1])[tCentroids]]},{centroid[(Subscript[C, 2])[tCentroids]]}},
PlotTheme->"myTheme",
PlotMarkers->centroidMarkers,
PlotStyle->Opacity[0.2]
];

(* New centroid due to the temporary exchange *)
centroid1=centroid[C1Temp];
centroid2=centroid[C2Temp];

(* Text for the variance values *)
varianceStepText={Text[
Apply[StringJoin,ToString[#,StandardForm]&/@{
Style["(Subscript[D, var])((Subscript[C, 1])) + ",colorC1],
Style["(Subscript[D, var])((Subscript[C, 2]))",colorC2],
"\n",
Style[ToString[Round[var1Temp,0.01]],colorC1],
" + ",
Style[ToString[Round[var2Temp,0.01]],colorC2],
" = "<>ToString[Round[var1Temp+var2Temp,0.01]],
({{\[Piecewise], ({{" > ", var1Temp+var2Temp>variance[⌊t⌋]}, {" < ", True}})}}),
ToString[Round[variance[⌊t⌋],0.01]],
"\n⇒ ",
({{\[Piecewise], ({{"reject exchange", var1Temp+var2Temp>variance[⌊t⌋]}, {"accept exchange", True}})}})
}],
Scaled[{0.25,0.7}]
]};
];

title=({{\[Piecewise], ({{"starting situation", t==0}, {"no change, reached (Subscript[n, min])", !checkNmin[]}, {"select point", tFraction==0.25}, {"change cluster label", tFraction==0.5}, {"calculate variance", tFraction==0.75}, {"result", True}})}});

Show[
(* Points in cluster *)
ListPlot[{
Callout[#,Superscript[Style["x",FontSlant->Italic],Position[data,#][[1,1]]]]&/@(Subscript[C, 1])[tCentroids],
Callout[#,Superscript[Style["x",FontSlant->Italic],Position[data,#][[1,1]]]]&/@(Subscript[C, 2])[tCentroids]
},
PlotTheme->{"myTheme","Grid"},
AspectRatio->1,
PlotLegends->PointLegend[97,{"(Subscript[C, 1])","(Subscript[C, 2])"},LegendMarkerSize->18,LegendMargins->0],
AxesLabel->{"(Subscript[x, 1])","(Subscript[x, 2])"},
PlotLabel->"t = "<>ToString[t]<>" ("<>title<>")",
PlotRange->{{-0.1,Max[data\[Transpose][[1]]]+0.5},{-0.1,Max[data\[Transpose][[2]]]+1}},
Epilog->{
Directive[FontFamily->"Libertinus Serif",FontSize->18],
{Text["(Subscript[D, var])("<>ToString[⌊t⌋]<>") = "<>ToString[Round[variance[⌊t⌋], 0.01]],Scaled[{0.15,0.95}]]},
varianceStepText
}
],

(* Cluster centroids *)
ListPlot[{{Callout[centroid1,"(Subscript[c, 1])",Left]},{Callout[centroid2,"(Subscript[c, 2])",Left]}},
PlotTheme->"myTheme",
PlotMarkers->centroidMarkers
],

centroidsTemp,

(* Current marked point *)
ListPlot[{x[xPos]},
PlotLegends->PointLegend[97,{"Current point"},LegendMarkerSize->15,LegendMargins->3],
PlotTheme->"myTheme",
PlotMarkers->{
Graphics[{
EdgeForm[Directive[Opacity[0.5],Thickness[0.2],Red]],
FaceForm [pointColor],
Disk[]
}],
0.025}
],

varianceLines
]
];