Skip to content

induced.subgraph and subgraph.edges don't adjust layout if layout is matrix #219

@ahmontgo

Description

@ahmontgo

I've been plotting multiple subgraphs while attempting to retain layout values, and came across an interesting bug. If g$layout is a matrix, vertex deletion doesn't modify it, which produces odd results. For example:

g <- make_ring(10)
g$layout <- layout_in_circle(g)
plot(induced.subgraph(g,c(1:9)))

The "ghost" node 10 is still plotted, picking up the label of the first vertex to boot!

Workaround is to manually remove the node from layout:
g2 <- induced.subgraph(g,1:9)
g2$layout <- g2$layout[1:9,]
plot(g2)

Similar but slightly more complex manual removal needs to occur when subgraph.edges is used:
g3 <- subgraph.edges(g,1:8)
g3$layout <- g3$layout[V(g)[inc(1:8)],]
plot(g3)

Expected behavior would be for plot() to ignore any "extra" vertices in layout. But depending on internal representation, there may be no way of doing so. In that case, subgraph.edges and induced.subgraph should probably modify any g$layout if g$layout is a matrix.

I'd offer a patch, but my C is very shaky.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions