I am using the igraph
and ggraph
package to plot an arc diagram. I am having trouble with the geom_node_text
parameter because, as the length of the text label increases, the graph lower margin will not increase accordingly. So if the label for a node is a bit long, it ends up getting clipped off from the plot.
Here is a reproducible example using the karate
sample data from the igraphdata
package.
data(karate)
ggraph(karate, layout="linear")+
geom_edge_arc(aes(edge_width=weight), edge_alpha=0.5, fold=T)+
geom_node_point(aes(size=strength(karate), color=as.factor(color)))+
geom_node_text(aes(label=name), angle=90, hjust=1, nudge_y = -0.2, size=4)+
theme_void()+theme(legend.position = "none")
I have already tried to change the plot margins via the theme(plot.margin=)
but the labels get clipped off anyway.
You can set coord_cartesian(clip = "off")
in your plot and expand the plot margins:
data(karate)
ggraph(karate, layout = "linear") +
geom_edge_arc(aes(edge_width = weight), edge_alpha = 0.5, fold = TRUE) +
geom_node_point(aes(size = strength(karate), color = as.factor(color))) +
geom_node_text(aes(label = name), angle = 90, hjust = 1, nudge_y = -0.2, size = 4) +
coord_cartesian(clip = "off") +
theme_void() +
theme(legend.position = "none", plot.margin = unit(rep(30, 4), "points"))