Nearest Neighbor Graphs
Generate the nearest neighbor graph of a collection of arbitrary data with the new NearestNeighborGraph function in Version 11.
Construct the nearest neighbor graph for the countries of South America.
In[1]:=
locs = CountryData["SouthAmerica"];
coords = EntityValue[locs, "Position"][[All, 1, {2, 1}]];
In[2]:=
g = NearestNeighborGraph[locs, VertexCoordinates -> coords]
Out[2]=
Style the network atop the continent.
show complete Wolfram Language input
In[4]:=
Graph[g, opts]
Out[4]=
Show the 3-nearest neighbor graph for a collection of random colors.
In[5]:=
colors = RandomColor[50]
Out[5]=
In[6]:=
NearestNeighborGraph[colors, 3, VertexShapeFunction -> "Name"]
Out[6]=