2
votes

This may sound like a very minor detail of a question, however I am trying to make this graph look at clean as possible, and any feedback is appreciated. I am working on creating network graphs in R for basketball. I made this post a few days ago - Draw beautiful network graphs in R - with shows the type of graph I am trying to mimic.

Using the igraph package, I have been able to recreate the graph for the most part. Example below, with the dataframe I am using too:

library(igraph)
nba.nodes <- data.frame(id = c('s01', 's02', 's03', 's04', 's05'),
                        color = c('darkred', 'darkblue', 'darkgreen', 'darkorange',  'darkmagenta'),
                        names = c('Jarrett\nJack', 'Tim\nHardaway', 'Courtney\nLee', 'Kristaps\nPorzingis', 'Enes\nKanter'))

nba.edges <- data.frame(from = c('s01', 's01', 's01', 's01', 
                                 's02', 's02', 's02', 's02',
                                 's03', 's03', 's03', 's03',
                                 's04', 's04', 's04', 's04',
                                 's05', 's05', 's05', 's05'),
                        to = c('s02', 's03', 's04', 's05',
                               's01', 's03', 's04', 's05', 
                               's01', 's02', 's04', 's05',
                               's01', 's02', 's03', 's05',
                               's01', 's02', 's03', 's04'),
                        width = sample(1:12, 20, replace = TRUE))

nba.net <- graph_from_data_frame(d = nba.edges, vertices = nba.nodes, directed = T)

# ignore the layout = l, i have this commented out, was just testing it   
# l <- layout_in_circle(nba.net)
plot(nba.net, # layout = l,
     vertex.size = 20,
     edge.curved = 0.3, 
     vertex.label = V(nba.net)$names,
     vertex.label.dist = 4,
     vertex.label.font = 2)

As you can see, the plot is nice but I am very unhappy with how the edge.curved parameters works. Rather than plotting a smooth, curved edge line similar to those in the graph in the link I shared, the edges are these bent lines... the larger i set the parameter edge.curved, the more bent the line... not the curve i was hoping for.

As you can tell, the edges in the graph in the link i shared appear to be perfect curves (perfect in the sense that they have the curvature of a circle). Is there any way I could do this using igraph? any help is appreciated with this, thanks!

1

1 Answers

0
votes

If you are trying to get a better picture on the screen, I have no help. But if you are trying to save the picture (say for inclusion in a paper or PowerPoint) you can get a picture without the aliasing by using a different graphics device. Try:

png('Graph.png', 500, 500, type='cairo')
plot(nba.net, # layout = l,
     vertex.size = 20,
     edge.curved = 0.3, 
     vertex.label = V(nba.net)$names,
     vertex.label.dist = 4,
     vertex.label.font = 2)
dev.off()

And look for the output in the current directory (use getwd())