2
$\begingroup$

I have the following code:

flagAsia = Rasterize /@(Ctrl+=  Asia flags) (* get the Asia flags with free form input *)

NearestNeighborGraph[flagAsia, 2, VertexLabels -> Table[i -> ImageResize[flagAsia[[i]], 70], {i, 1, Length@flagAsia}]]

With VertexLabels -> Table[i -> ImageResize[flagAsia[[i]], 70], {i, 1, Length@flagAsia}], I meant to label the graph with flag icon. But this command seems not evaluated.

What is the problem?

Platform: Ubuntu 19.04, Mathematica 12.1

Thanks.

$\endgroup$
1

1 Answer 1

2
$\begingroup$

As noted in comments by Chip Hurst, see this answer by Chip re why your code does not work.

An alternative way to use NearestNeighborGraph with country flags as vertex labels and geo-positions as vertex coordinates:

countries = EntityList @ EntityClass["Country", "Asia"]; 

resizedflags = Rasterize[#, ImageSize -> 30, ImageResolution -> 100, 
    Background -> None] & /@ EntityValue[countries, "FlagImage", "EntityAssociation"];

vlabels = Normal[KeyValueMap[# -> Placed[{CanonicalName@# , #2}, {Tooltip, Center}] &]@
    resizedflags];

vcoords = Normal[(Reverse@*First) /@  
    EntityValue[countries, "Position", "EntityAssociation"]]; 

NearestNeighborGraph[countries, 2, 
 VertexLabels -> vlabels, VertexCoordinates -> vcoords, ImageSize -> 800]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks. I have got the key points: (1) the element is not integer i; (2) turn to VertexLabels and VertexCoordinates to compose the graph. $\endgroup$
    – PureLine
    Mar 25, 2020 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.