4

I'd like to draw a wheel graph with directed arcs with a given n where n represents the nodes around the hub node. There is a similar question whose answer is provided for the undirected wheel graph.

\documentclass[tikz,margin=3mm]{standalone}

\usetikzlibrary{graphs,graphs.standard,calc}
\begin{document}
\begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
    \graph  [nodes={circle,fill=black!25}, edges={black!60, semithick}, clockwise, radius=8em,
    n=9, p=0.3] 
        { subgraph C_n [n=6,m=3,clockwise,radius=2cm,name=A] };
        \node at  ($(A 1)!.5!(A 4)$) (C){};
        \foreach \i in {1,2,...,6}{
        \draw (C)-- (A \i); }
        \draw [fill=black!25](C) circle (0.4em);
\end{tikzpicture}
\end{document}

Firstly, how can turn each edge into two directed arcs (please see the image below for a reference)? Secondly, when I change the parameter n, the visualization of the wheel looks pretty odd (please see the second image). Is there a way to arrange this code in the sense that the hub node is automatically centralized around the neighbor nodes?

enter image description here

enter image description here

1 Answer 1

4

Here is my interpretation of your requirements. Rather than using subgraph, which seemed to be problematic for getting two edges between each vertex, I used necklace routing, and developed an answer based on @AndréC's answer here: Plot a 4-regular directed network. A graph with an odd number of vertices presents the small challenge of finding the centre. I used TikZ's barycentric co-ordinate system barycentric cs to define the mid-point between vertices 1, 4 and 7. Comments on the sequence of steps to build the graph are included in the code.

%Adapted from https://tex.stackexchange.com/a/527809/
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary {graphs,graphdrawing}
\usegdlibrary {circular,routing}
\usetikzlibrary{arrows.meta,bending}
\tikzset{every edge/.append style = {>={Stealth[round,sep,bend]}}}

\begin{document}
\begin{tikzpicture}
% Create the verticies and include the edges bending right
\graph [simple necklace layout, node distance=1.5cm,
necklace routing,grow'=south,edges={bend right=10}]{ 
1 -> 2  -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 1
};
%reuse the existing verticies and include the edges bending left
\graph [use existing nodes,edges={bend left=15}]{
1 <- 2  <- 3 <- 4 <- 5 <- 6 <- 7 <- 8 <- 9 <- 1
};
%Create a node at the centre
\node[draw,circle,radius=2mm] (C) at
(barycentric cs:1=0.5 ,4=0.5,7=0.5) {};
%Reuse the existing nodes and draw the edges bending right from the outer circle of nodes to the centre (C)
\graph [use existing nodes,edges={bend right=15}]{
1 -> C, 2 -> C, 3 -> C, 4 -> C, 5 -> C, 6 -> C, 7 -> C, 8 -> C, 9 -> C
};
%Reuse the existing nodes and draw the edges bending left from the outer circle of nodes to the centre (C)
\graph [use existing nodes,edges={bend left=15}]{
1 <- C, 2 <- C, 3 <- C, 4 <- C, 5 <- C, 6 <- C, 7 <- C, 8 <- C, 9 <- C
};
\end{tikzpicture}
\end{document}

Which gives this: enter image description here

2
  • I am receiving an error at line \usegdlibrary {circular,routing} when I copy and paste your code on Overleaf. Is there an extra document that I should include in my project?
    – ball_jan
    Commented Jul 16, 2021 at 14:59
  • For the missing graph drawing libraries, I suggest you ask the Overleaf help desk, or see if you can find them at the tikz-pgf repository on github.
    – Ross
    Commented Jul 16, 2021 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .