Maths formulas or symbols for labelling edges or vertices

Hi,
as explained in the title I would like to label the edges or vertices using maths symbols, such as those given by latex2exp.

Is it possible ?
Thank you in advance
René

In R, Python, Mathematica or some other language?

HI,

As a starting point, my question was for R. I found solutions with Latex and package tikz that are promising. I keep on being intersted by solutions with R.
Thank you

:wave: @Gypaetus_barbatus

What seems promising is using the ggraph package together with latexexp. An example below, that I created by mixing Edges • ggraph and the latexexp docs.

library("ggraph")
#> Loading required package: ggplot2
library("tidygraph")
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library("latex2exp")
simple <- create_notable('bull') |> 
  mutate(name = c('Thomas', 'Bob', 'Hadley', 'Winston', 'Baptiste')) |> 
  activate(edges) |> 
  mutate(type = sample(c('friend', 'foe'), 5, TRUE))

ggraph(simple, layout = 'graphopt') + 
  geom_edge_link(aes(label = type), 
                 angle_calc = 'along',
                 label_dodge = unit(2.5, 'mm'),
                 arrow = arrow(length = unit(4, 'mm')), 
                 end_cap = circle(3, 'mm')) + 
  geom_node_point(size = 5) +
  ggtitle(TeX(r'(Using $\LaTeX$ for plotting in ggplot2. I $\heartsuit$ ggplot!)'))

Created on 2024-03-18 with reprex v2.1.0

2 Likes

Hi Maelle,

thank you for your reply. I see you use latex in the title. Would it be possible to use it to label the edges, for example having \theta_k^i instead of ‘foe’ ?