Skip to contents

Plotting in {EGAnet} has become much more flexible by passing on most arguments to {GGally}’s ggnet2 (some arguments might not change to keep a consistent {EGAnet} style to the plots). This Wiki walks through some of the flexibility available in {EGAnet}’s plots. This demonstration is only the start – you can use these plots as the foundation for your own creations. These examples focus solely on EGA plotting but apply to all *EGA plots.

Basic Plot

# Load necessary packages
library(EGAnet); library(GGally); library(ggplot2)

# Estimate EGA
ega.wmt <- EGA(wmt2[,7:24], plot.EGA = FALSE)

# Plot
plot(ega.wmt)

Legend

Change Names

plot(ega.wmt, legend.names = c("Dimension 1", "Dimension 2"))

Remove legend

plot(ega.wmt) + theme(legend.position = "none")

Handling legend title and text can be done using the standard ?ggplot2::theme arguments

Title

Basic Title

plot(ega.wmt) + ggtitle("EGA Title")

Adjusted Title (centered, larger size, bold)

plot(ega.wmt) + 
  ggtitle("Better EGA Title") +
  theme(plot.title = element_text(size = 14, face = "bold", hjust = 0.5))

Layout

For all available layout options, see ?sna::gplot.layout. Remove gplot.layout. to use the layout (e.g., gplot.layout.circle = layout = "circle")

Circle

plot(ega.wmt, layout = "circle")

Eigen

plot(ega.wmt, layout = "eigen")

Nodes

Colors

Change Colors Using Color Palette

plot(ega.wmt, color.palette = "blue.ridge2")

Change Colors Using HEX Codes

plot(ega.wmt, node.color = c("#F5815A", "#47BCC9"))

For quick color palette ideas, check out this color palette generator

Size

plot(ega.wmt, node.size = 12)

Change Size based on Node Strength

plot(ega.wmt, node.size = colSums(ega.wmt$network)^2 * 16)

Edges

Size

plot(ega.wmt, edge.size = 12)

Transparency

plot(ega.wmt, edge.alpha = 0.1)

Colors and Line Type

plot(
  ega.wmt, edge.alpha = 1,
  edge.lty = c( # line type
    "dashed", # positive edge first
    "solid" # negative edge second
  ),
  edge.color = c( # color
    "pink", # positive edges first
    "black" # negative edges second
  )
)

Positive Only

plot(
  ega.wmt,
  edge.color = c(
    "darkgreen", # positive edges (default color)
    "white" # negative edges second
  )
)

Negative Only

plot(
  ega.wmt, edge.alpha = 1, # used to increase visibility 
  edge.color = c(
    "white", # positive edges first
    "red" # negative edges (default color)
  )
)