Can Julia plot this kind of graph?
The most direct fit might be TikzGraphs.jl.
If you are willing to do the plot manually, you can probably do it with anything, Plots.jl or Makie.jl.
In Makie you would for example use the commands text
, arrows
and poly
.
Now, if you want the positioning to be more automatic, there is also this package which can compute the positions for a given input graph: GitHub - oxinabox/LayeredLayouts.jl: Layered Layout Algorithms for Directed Acyclic Graphs
Well, nearly everything is possible, it’s just that some things are more work than others. Here’s my attempt.
I couldn’t get two lines of text in a box - well, I’d have to write more lines of code, and I took the easy way out by not bothering.
Arguably it’s more work to write this code than to draw the diagram directly in a graphics editor. However, if you had to draw a thousand of them, doing it in code might better…
For this particular diagram, defining three points was a bit easier than playing with the NetworkLayout algorithms…
Julia code
using Karnak, Graphs
g = Graph(3, 3)
vertexlabels = ["Sex", "Aggregate spatial ability", "Mean performance ¹"]
edgelabels = ["0.16*", "0.64**", "-0.7"]
@drawsvg begin
background("grey95")
sethue("black")
fontsize(14)
fontface("BarlowCondensed-Bold")
drawgraph(g,
layout=[Point(-150, 50), Point(0, -50), Point(150, 50)],
vertexfunction = (v, c) -> begin
@layer begin
sethue("white")
box(c[v], 150, 50, :fill)
end
box(c[v], 150, 50, :stroke)
text(vertexlabels[v], c[v], halign=:center)
end,
edgefunction = (edgenumber, edgesrc, edgedest, from::Point, to::Point) -> begin
arrow(from, to, decorate = () -> ngon(O, 10, 3, 0, :fill))
label(edgelabels[edgenumber], slope(midpoint(from, to), O), midpoint(from, to), offset=-50)
end)
text("mediation path analysis", boxbottomleft() + (20, -25))
text("¹ Santa Barbara Solids Test", boxbottomleft() + (20, -10))
translate(boxtopleft() + (20, 20))
juliacircles(10)
end 500 300