LRomine
LRomine

Reputation: 11

Is there a simple way to add a legend explaining vertex colors to a fruchterman reingold plot in R?

I have a fruchterman reingold plot of 20 random students' extra curricular activities with the vertex color based on their final grades (numeric, ranging from 0-20) in an associated data set. Is there a way to to display a legend that prints the range for each vertex color?

library(igraph)

a <- graph.adjacency(sport,mode="undirected")

plot(a,layout=layout.fruchterman.reingold, vertex.size=6, vertex.color=portsmall$G3)

Here is a impage of my plot with colored vertices:

https://i.sstatic.net/0vc3j.png

Upvotes: 1

Views: 1825

Answers (1)

Spacedman
Spacedman

Reputation: 94202

You can just use the legend function. For example:

legend("top",legend=c(1,2,3),fill=c("red","green","blue"))

You'll need to work out the precise nature of the parameters since we don't have your data so we can't guess. Read the docs for legend for more.

Upvotes: 1

Related Questions