This space next to walls reduces the chance of damage to the wire by in new construction or future remodeling. If these issues are not relevant in your case, it is OK to put wires within 3 inches of the wall. Definitely stay at least 4" from the toilet ring. Another good reason for the gap is to save you money. In most cases, you do not stand closer than 6” to a wall so you can use less wire by leaving a space.