# How to plot this diagram?

**URL:** <https://discourse.julialang.org/t/how-to-plot-this-diagram/86990>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [September 9, 2022, 2:12pm UTC](https://discourse.julialang.org/t/how-to-plot-this-diagram/86990 "2022-09-09T14:12:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [September 9, 2022, 2:12pm UTC](https://discourse.julialang.org/t/how-to-plot-this-diagram/86990/1 "2022-09-09T14:12:33Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/d/d/ddcc171b22475890068acd4716585a6b3c5ae1a2.jpeg)

Can Julia plot this kind of graph?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 9, 2022, 2:48pm UTC](https://discourse.julialang.org/t/how-to-plot-this-diagram/86990/2 "2022-09-09T14:48:19Z")

</div>

The most direct fit might be [TikzGraphs.jl](https://nbviewer.org/github/JuliaTeX/TikzGraphs.jl/blob/master/doc/TikzGraphs.ipynb).

* * *

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](https://github.com/oxinabox/LayeredLayouts.jl)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [September 9, 2022, 5:24pm UTC](https://discourse.julialang.org/t/how-to-plot-this-diagram/86990/3 "2022-09-09T17:24:25Z")

</div>

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. 🙂

 ![Screenshot 2022-09-09 at 18.21.40](https://global.discourse-cdn.com/julialang/original/3X/a/0/a0e48ca41b0c8e91bb1218e6b91ca861d9dd4371.png)

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**
>
> ```julia
> 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
> 
> ```
