6
$\begingroup$

I have a bunch of high dimensional data and I want to use a graph to plot relationships among that data. To keep things small, say the data is

d[x_, y_] := Total[Abs[x - y]];
data = RandomReal[{0, 1}, {10, 5}];
RelationGraph[0.2 < d[#1, #2] < 1.5 &, data, data]

This draws a nice graph of all the elements whose distance apart is between 0.2 and 1.5. If I want to label the graph with the index number, then

RelationGraph[0.2 < d[#1, #2] < 1.5 &, dist, dist, VertexLabels -> "Index"]

works fine. But if I want to use my own labels, Mathematica does not draw the graph and simply returns the input unchanged. For example, neither of these:

RelationGraph[0.2 < d[#1, #2] < 1.5 &, dist, dist, 
              VertexLabels -> {1 -> "this", 2 -> "that"}]

RelationGraph[0.2 < d[#1, #2] < 1.5 &, dist, dist, 
              VertexLabels -> Table[i -> Subscript[v, i], {i, 5}]]

return any graph. Is there a trick to using VertexLabels? Or do I need to search for another way to draw the graphs?

$\endgroup$
1
  • 1
    $\begingroup$ You need Table[dist[[i]] -> Subscript[v, i], {i, 5}] - it takes the element's value not the position. $\endgroup$
    – flinty
    Commented Jul 1, 2020 at 22:07

1 Answer 1

6
$\begingroup$
RelationGraph[0.2 < d[#1, #2] < 1.5 &, data, data, 
 VertexLabels -> {data[[1]] -> "this", data[[2]] -> "that"}]

enter image description here

RelationGraph[0.2 < d[#1, #2] < 1.5 &, data, data, 
 VertexLabels -> MapIndexed[# -> Subscript[v, #2[[1]]] &, data]]

enter image description here

$\endgroup$

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.