2

I've recently been learning text mining with tidytext. Today, I encountered the following:

set.seed(2017)
ggraph(bigram_graph, layout="fr") + geom_edge_link() + geom_node_point() + 
geom_node_text(aes(label=name), vjust=1, hjust=1)

I've used the set.seed() function with other functions like sample(). But here, I don't understand why ggraph should be used with set.seed(). Can anyone help me?

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
No Ru
  • 37
  • 3
  • 6
    I believe in (the default layout of) a graph (i.e. how nodes are placed on the plot) is random; so setting a fixed seed ensures that graphs are identical. It's easy to check: Remove the `set.seed(2017)` statement and see if `ggraph(...) + ...` produces the same output when re-running multiple times. – Maurits Evers Mar 06 '19 at 12:47
  • 1
    Ahhhh! Thank you so much! – No Ru Mar 06 '19 at 13:05
  • @MauritsEvers Could you please make your comment an answer? That's what it actually is, and as far as I can tell, it is the correct answer. – Tripartio Jun 17 '20 at 13:32

1 Answers1

1

We use a set.seed function because the results vary when performing a random performance. Figuratively speaking, imagine planting seeds. You can sow seeds anywhere in the land. The first seed planted and the second seed planted produce clearly different results. This is because the shape of the stem and the leaf are different. If you use the set.seed function, you will get the same results.

Sang won kim
  • 524
  • 5
  • 21