Mathematica Subgraph "Neat Example" not working properly in Mathematica 12

sg = Subgraph[g,
 Complement[VertexList[g],
   VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]];

The issue seems to be that Subgraph inherits the GraphLayout option value from the parent graph:

PropertyValue[sg, GraphLayout]

{"GridEmbedding", "Dimension" -> {25, 50}}

and, somehow, the vertex layout defaults to something weird when the number of vertices do not match the length of the coordinate list produced by the layout procedure.

So, you can

  1. add the option GraphLayout -> Automatic (or use your desired setting):

SetProperty[sg, GraphLayout -> "SpringElectricalEmbedding"]

enter image description here

  1. remove the GraphLayout property from g:

Subgraph[RemoveProperty[g, GraphLayout],
  Complement[VertexList[g],
    VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]]

enter image description here

  1. use the option VertexCoordinates to retain vertex coordinates in g:

Subgraph[g,
 Complement[VertexList[g],
  VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]], 
 VertexCoordinates -> {v_ :> PropertyValue[{g, v}, VertexCoordinates]}]

enter image description here


How about filing a bug with Wolfram Research? It only takes a few minutes. In a notebook, click Help, Give feedback..., fill out the rest of the form (most is completed for you), and then click "Submit." You don't need a service contract to file a bug, and there is no guarantee the Wolfram will see this Stack Exchange entry.