Graphene and hexagonal boron nitride are typical conductor and insulator, respectively, while their hybrids hexagonal boron carbonitride are promising as a semiconductor. Here we demonstrate a direct chemical conversion reaction, which systematically converts the hexagonal carbon lattice of graphene to boron nitride, making it possible to produce uniform boron nitride and boron carbonitride structures without disrupting the structural integrity of the original graphene templates. We synthesize high-quality atomic layer films with boron-, nitrogen- and carbon-containing atomic layers with full range of compositions. Using this approach, the electrical resistance, carrier mobilities and bandgaps of these atomic layers can be tuned from conductor to semiconductor to insulator. Combining this technique with lithography, local conversion could be realized at the nanometre scale, enabling the fabrication of in-plane atomic layer structures consisting of graphene, boron nitride and boron carbonitride. This is a step towards scalable synthesis of atomically thin two-dimensional integrated circuits.