Carl
Carl

Reputation: 109

How to change the layout of a ggraph network plot?

I'm working on a report needs to plot a network using the ggraph package in r. My code is:

net <- graph_from_data_frame(d=edges,vertices=nodes,directed = F)
ggraph(net) + 
geom_edge_link(aes(alpha=color)) + 
geom_node_point(aes(shape=as.factor(gender),alpha=location)) 

and I get a plot:, looks like a mushroom :D, is there any way can change the network to another shape?

Upvotes: 1

Views: 1012

Answers (2)

ppanko
ppanko

Reputation: 372

ggraph has several built in layouts which you can see in this help page: ?create_layout.

It also pulls in several layout algorithms from igraph which you can browse in the appropriate help page: ?layout_tbl_graph_igraph.

In either case, you can specify them in either the ggraph function:

ggraph(net, layout = "fr")

Or use the create_layout function:

create_layout(net, layout = "drl")

Upvotes: 2

rjen
rjen

Reputation: 1972

Try setting the layout, e.g. ggraph(net, layout = 'kk').

Upvotes: 0

Related Questions