I'm working on plotting a network graph, and am having trouble reading the edge labels. Is there a way to define a background color or opaque area behind the edge labels to make them more readable? Thanks!
```
g_ex <- tibble::tibble(from = rep("a", 3), to = c("x", "y", "z"), weight = seq(0, 0.2, 0.1)) %>%
igraph::graph_from_data_frame(.)
plot.igraph(g_ex, edge.label = igraph::get.edge.attribute(g_ex, "weight"))
```
[![Directed graph with one parent node "a" and three child nodes "x", "y", & "z". Edges have weights of 0.0, 0.1, & 0.2, respectively.][1]][1]
[1]: https://i.stack.imgur.com/asCxe.png
UPDATE
One important consideration I neglected in initial example is that vertices need to be conditionally formatted based on a vertex attribute. Updated reprex below, differences in node size can be ignored.
'''
# load pkgs
library(tidyverse)
library(plotrix)
library(igraph)
# define and register ellipse w/ igraph, from https://stackoverflow.com/a/48469289/9806500
myellipse <- function(coords, v = NULL, params) {
vertex.color <- params("vertex", "color")
if (length(vertex.color) != 1 && !is.null(v)) {
vertex.color <- vertex.color[v]
}
vertex.size <- 1 / 30 * params("vertex", "size")
if (length(vertex.size) != 1 && !is.null(v)) {
vertex.size <- vertex.size[v]
}
plotrix::draw.ellipse(
x = coords[, 1],
y = coords[, 2],
a = vertex.size,
b = vertex.size / 2,
col = vertex.color
)
}
igraph::add_shape("ellipse", clip = shapes("circle")$clip, plot = myellipse)
# define graph
df_e <- tibble::tibble(from = rep("a", 3), to = c("x", "y", "z"), weight = seq(0, 0.2, 0.1))
df_v <- tibble::tibble(name = c("a", "x", "y", "z"), shape = c("square", "ellipse", "ellipse", "ellipse"))
g_ex <- igraph::graph_from_data_frame(d = df_e, vertices = df_v)
# plot
igraph::plot.igraph(g_ex, edge.label = igraph::get.edge.attribute(g_ex, "weight"), vertex.shape = igraph::get.vertex.attribute(g_ex, "shape"))
```