2
$\begingroup$

I'm trying to put names inside circles and it's proving to be difficult to say the least

CycleGraph[5, 
 VertexLabels -> {1 -> "Adam", 2 -> "bob", 3 -> "carl", 
   4 -> "danny", 5 -> "ellan"}, DirectedEdges -> True, 
 VertexLabels -> Placed[Automatic, Center], VertexSize -> .45]

But it's putting the names outside of the circles, when I want them in the center. I'm sure I'm missing something basic

$\endgroup$
2
  • $\begingroup$ try VertexLabels -> ({1 -> "Adam", 2 -> "bob", 3 -> "carl", 4 -> "danny", 5 -> "ellan"} /. Rule[a_, b_] :> Rule[a, Placed[b, Center]]) or VertexLabels -> MapAt[Placed[#, Center] &, {1 -> "Adam", 2 -> "bob", 3 -> "carl", 4 -> "danny", 5 -> "ellan"}, {All, 2}]? $\endgroup$
    – kglr
    Nov 8, 2022 at 19:55
  • $\begingroup$ @kglr, my output for that is no labels at all, just the empty circles $\endgroup$
    – Wombles
    Nov 8, 2022 at 19:56

1 Answer 1

4
$\begingroup$

You should add Placed in the first VertexLabels:

CycleGraph[5, 
 VertexLabels -> 
  MapThread[#1 -> Placed[#2, Center] &, {Range[5], {"Adam", "bob", 
     "carl", "danny", "ellan"}}], DirectedEdges -> True, 
 VertexSize -> .45, VertexLabelStyle -> 20]

or replace vertices:

VertexReplace[CycleGraph[5, DirectedEdges -> True], 
 Thread[Range[5] -> {"Adam", "bob", "carl", "danny", "ellan"}], 
 VertexLabels -> Placed[Automatic, Center], VertexSize -> .45, 
 VertexLabelStyle -> 20]

VertexReplace[CycleGraph[5, DirectedEdges -> True], 
 Thread[Range[5] -> {"Adam", "bob", "carl", "danny", "ellan"}], 
 PlotTheme -> "NameLabeled", VertexSize -> .45, 
 VertexLabelStyle -> 20]
$\endgroup$

Your Answer

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

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