gridgraphics icon indicating copy to clipboard operation
gridgraphics copied to clipboard

igraph plot with NA labels for edges

Open marcosmolla opened this issue 6 years ago • 3 comments

Hi, I ran into an issue with igraph in combination with cowplot.

I tried to plot a simple igraph network and found that there were NA labels added along the network edges. I first filed this under the cowplot package (see this issue here), but @clauswilke recommend to file it here. Any recommendations?

Thanks everyone!!

Here is my code example:

library(igraph)
library(cowplot)
net<- graph_from_literal(A-B, A-C, A-D,
                         B-E,B-F,
                         C-G,G-H)

net_plot <- ~{
  par(mar=c(0,0,0,0)+.1)
  plot(net, vertex.label.color="white", layout=layout_as_tree(net,root=1), edge.color="black", margin=c(0,0,0,0))
}

save_plot(ggdraw(net_plot), filename="~/Desktop/tst.pdf",base_height=5, base_width=6)```

marcosmolla avatar Aug 06 '19 21:08 marcosmolla

That goes surprisingly deep. Turns out that grid::grid.text() is the culprit. I will fix that, but it will not be released until next year, so in the meantime I have also placed a fix in 'gridGraphics' (0.4-2), which should be available here (on github). Does that work for you ?

pmur002 avatar Aug 06 '19 22:08 pmur002

I just installed the github version and yes that worked. Fantastic!! Thank you!

marcosmolla avatar Aug 06 '19 22:08 marcosmolla

Just FYI, turns out that other code ('ggplot2') is relying on 'grid' drawing "NA" for grid.text(NA ), so this is likely to remain a 'gridGraphics' fix.

pmur002 avatar Aug 08 '19 21:08 pmur002