This example demonstrates how to add and remove nodes and links from a force-directed layout. The graph initially appears with three disconnected nodes A, B and C. After one second, the three are connected in a loop. At two seconds, node C is removed, along with the links A-C and B-C. At three seconds, node C is reintroduced, restoring the original links A-C and B-C. Every subsequent second alternates between these two steps.
This example uses the general update pattern for data joins. See also modifying a force layout with transitions.
I've just created a fork of this example, heavily commented, giving what I hope is a detailed explanation of the important concepts: https://gist.github.com/rdpoor/3a66b3e082ffeaeb5e6e79961192f7d8
(And I see that it appears in bl.ocks "by magic". Very nice!)