In-plane and vertically stacked heterostructures of graphene and hexagonal boron nitride (h-BN-G and G/h-BN, respectively) are both recent focuses of graphene research. However, targeted synthesis of either heterostructure remains a challenge. Here, via chemical vapour deposition and using benzoic acid precursor, we have achieved the selective growth of h-BN-G and G/h-BN through a temperature-triggered switching reaction. The perfect in-plane h-BN-G is characterized by scanning tunnelling microscopy (STM), showing atomically patched graphene and h-BN with typical zigzag edges. In contrast, the vertical alignment of G/h-BN is confirmed by unique lattice-mismatch-induced moiré patterns in high-resolution STM images, and two sets of aligned selected area electron diffraction spots, both suggesting a van der Waals epitaxial mechanism. The present work demonstrates the chemical designability of growth process for controlled synthesis of graphene and h-BN heterostructures. With practical scalability, high uniformity and quality, our approach will promote the development of graphene-based electronics and optoelectronics.