Electronic and Lattice Properties of Layered Hexagonal Compounds Under Anisotropic Compression: A First-Principles Study