1

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.stack.imgur.com/0vc3j.png

paqmo
  • 3,649
  • 1
  • 11
  • 21
LRomine
  • 11
  • 3
  • 1
    `graph.adjacency` is not a function in base R. Could you add the names of the packages you are using as well as a reproducible example? – lmo Nov 23 '16 at 15:52
  • the package is igraph, what do you need for a reproducible example (so I can make sure to provide everything)? – LRomine Nov 23 '16 at 16:25
  • There is a post about [minimum, complete, and verifiable examples](http://stackoverflow.com/help/mcve), as well as a post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – lmo Nov 23 '16 at 16:29

1 Answers1

1

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.

Spacedman
  • 92,590
  • 12
  • 140
  • 224