briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

geom_edgetext() fails to display on perfectly horizontal edges (e.g., in bipartite graphs) #33

Closed ArtemSokolov closed 5 years ago

ArtemSokolov commented 5 years ago

When an edge is perfectly horizontal, geom_edgetext() fails to display labels. Consider a simple graph:

G <- data.frame( x=0, xend=1, y=c(0,1), yend=c(0,1) )
ggplot( G, aes(x=x, y=y, xend=xend, yend=yend) ) +
    geom_edges() + theme_blank() +
    geom_edgetext( label="a" )           ## Fails to display

This is a potential problem for displaying bipartite graphs. The current workaround is to add a small amount of vertical perturbation to one of the ends:

G1 <- data.frame( x=0, xend=1, y=c(0,1), yend=c(0,1)+0.01 )
ggplot( G1, aes(x=x, y=y, xend=xend, yend=yend) ) +
    geom_edges() + theme_blank() +
    geom_edgetext( label="a" )          ## Now works as expected
briatte commented 5 years ago

Dear @ArtemSokolov

Thanks for reporting this, and all apologies for answering only now.

The issue is solved in the development version of ggnetwork, which will go on CRAN by the end of the summer. In the meantime, you can install it as follows:

# with `remotes`
remotes::install_github("briatte/ggnetwork")
# or with `devtools`
devtools::install_github("briatte/ggnetwork")

Again, all apologies for answering only now -- I have neglected the package in the past years, but remember seeing that issue a while back. It looks like it just fixed itself, perhaps through a ggplot2 update or something like that.