wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
704 stars 84 forks source link

igraph plot with NA labels for edges #142

Closed marcosmolla closed 5 years ago

marcosmolla commented 5 years ago

First of all, what a fantastic new functionality that allows to use cowplot to combine more than just ggplots (which already was quite awesome). I tried to plot a simple igraph network and observed that there are NA labels added along the network edges. Is there a way to get rid of them?


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)
clauswilke commented 5 years ago

This is a bug in the gridGraphics package. I suggest you file a bug report there.

library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union

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

net_plot <- function() {
  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))
}

net_plot()

library(gridGraphics)
#> Loading required package: grid
grid.echo(net_plot())

Created on 2019-08-06 by the reprex package (v0.3.0)