I have a really wordy network plot. I am basically trying to have it function as a sort of flow chart. I am trying to make its aesthetics both functional and pleasing, but I am having a difficult time. The legend's text is way too large and there is not enough space in the network for everything to be spaced out properly. Also, I want to make the background a different color.
The only solutions I have been able to find, however, require the ggnet2 package, but when I try to install the ggnet2 package, it says I cannot install that on this version of rStudio. When I tried to update my rStudio, it says that I have the most recent version of rStudio. I do not know what else to try.
Any help would be much appreciated! This is my code:
library(igraph)
library(RColorBrewer)
links <- data.frame(
source=c("Pubertal Hormones, Timing, and Development","Pubertal Hormones, Timing, and Development","Pubertal Hormones, Timing, and Development","Pubertal Hormones, Timing, and Development","Genetic Vulnerability","Genetic Vulnerability","Temperament","Temperament","Depressogenic Vulnerability","Negative Cognitive Style","Negative Cognitive Style","Objectified Body Consciousness","Objectifed Body Consciousness","Rumination","Peer Sexual Harassment","Peer Sexual Harassment"),
target=c("Genetic Vulnerability","Objectified Body Consciousness","Peer Sexual Harassment","Depressogenic Vulnerability","Temperament","Depressogenic Vulnerability","Negative Cognitive Style","Depressogenic Vulnerability","Gender Difference in Depression","Rumination","Depressogenic Vulnerability","Rumination","Depressogenic Vulnerability","Depressogenic Vulnerability","Objectified Body Consciousness","Gender Difference in Depression"),
importance=(sample(1:4, 16, replace=T))
)
V = c(links$source,
links$target) %>%
unique()
nodes <- data.frame( name=V,
carac=c(
rep("Biological Vulnerability",2),rep("Affective Vulnerability",3),rep("Cognitive Vulnerability",3),rep("Negative Life Events",2)) )
network <- graph_from_data_frame(d=links, vertices=nodes, directed=F)
coul <- brewer.pal(4, "Set3")
my_color <- coul[as.numeric(as.factor(V(network)$carac))]
plot(network, vertex.color=my_color,vertex.shape=c("vrectangle"),vertex.size=c(150),vertex.label.cex=c(0.5))
legend("bottom", legend=levels(as.factor(V(network)$carac)) , col = coul , bty = "n", pch=20 , pt.cex = 3, cex = 1, text.col=coul , horiz = TRUE, inset = c(0.1, 0.1))