Space charge induced electrostatic doping of two-dimensional materials: Graphene as a case study