DiagrammeR
DiagrammeR copied to clipboard
Making a correlation arrow
Hello,
I use diagrameR to make path diagrams, for which it is proving to be really helpful. However I have an issue I cannot figure out by myself.
I need to make a curve bidirectional arrow between two nodes in order to represent correlation, following the standard notation. But after searching for a long time, I don't see how I can do it.
Any advice?
Thank you.
@andpir55 try using this example to make a bidirectional arrow:
graph <-
create_graph() %>%
add_path(
n = 2,
edge_aes = edge_aes(
dir = "both",
arrowhead = "normal",
arrowtail = "normal",
color = "steelblue"))
graph %>% render_graph()
Unfortunately, there is no way to dependably force curved arrows.
I have a related question that probably has the same answer (but may help with the above question). Is there a way to dependably force straight arrows? I ask because I've had a similar issue, only I seem to be able to get either the curved arrows I want or the straight arrows, but not both.
This produces a straight edge graph (but the correlation edges overlap variable nodes)
grViz("
digraph {
graph [layout=neato, overlap=false, outputfirst= nodes]
ScoreK1[shape=box, pos='-2,0!']
ScoreK2[shape=box, pos='2,0!']
e1[shape=circle, pos='-3,1!']
e2[shape=circle, pos='3,1!']
a1[shape=circle, pos='-2,1!']
a2[shape=circle, pos='2,1!']
c1[shape=circle, pos='-1,1!']
c2[shape=circle, pos='1,1!']
e1->ScoreK1
e2->ScoreK2
a1->ScoreK1
a2->ScoreK2
a1->a2 [dir=both, label='1/0.5']
c1->ScoreK1
c2->ScoreK2
c1->c2 [dir=both, label='1']
}")
while this produces curved arrows (but for all edges, which is unorthodox for non-double headed arrows in these sorts of graphs).
grViz("
digraph {
graph [layout=neato, overlap=false, outputfirst= nodes, splines=curved]
ScoreK1[shape=box, pos='-2,0!']
ScoreK2[shape=box, pos='2,0!']
e1[shape=circle, pos='-3,1!']
e2[shape=circle, pos='3,1!']
a1[shape=circle, pos='-2,1!']
a2[shape=circle, pos='2,1!']
c1[shape=circle, pos='-1,1!']
c2[shape=circle, pos='1,1!']
e1->ScoreK1
e2->ScoreK2
a1->ScoreK1
a2->ScoreK2
a1->a2 [dir=both, label='1/0.5']
c1->ScoreK1
c2->ScoreK2
c1->c2 [dir=both, label='1']
}")
I'm just wondering if, given that forcing curvature doesn't seem to be doable, there is a way to force straightness for individual arrows?
It would be really great if forcing/customizing curved edges can be added as a feature. Otherwise not sure how useful this package is for what I was hoping to do :/
Indeed - it would help A LOT for plotting SEMs when representing correlations.
Hey, thought I'd poke in and see if this was still a priority? Working on a MS and was hoping to include some curved arrows. I was able to do them using the graphviz specification - see http://rpubs.com/jebyrnes/causal_mods, but, was hoping they could work with the general solution. Thanks again for an amazing package!
As far as I could tell, when using Graphviz through grViz()
, the only way to get curved arrows would be to post-process the output SVG (replacing the straight arrows with curved ones).
I'm toying with the idea of developing a new renderer based on SVG. Of course, that would be a big project but it would be the way to go. With that, we could also have rotated text (!) and other nice things. I'm experimenting with all of this in the omsvg package (https://github.com/rich-iannone/omsvg). If anybody here has some interest in SVG graphics and some ideas in how to migrate over to a new output renderer, please file some issues there!