Single-cell RNA-sequencing and in vivo functional imaging provide expansive but disconnected views of neuronal diversity. Here, we developed a strategy for linking these modes of classification to explore molecular and cellular mechanisms responsible for detecting and encoding touch. By broadly mapping function to neuronal class, we uncovered a clear transcriptomic logic responsible for the sensitivity and selectivity of mammalian mechanosensory neurons. Notably, cell types with divergent gene-expression profiles often shared very similar properties, but we also discovered transcriptomically related neurons with specialized and divergent functions. Applying our approach to knockout mice revealed that Piezo2 differentially tunes all types of mechanosensory neurons with marked cell-class dependence. Together, our data demonstrate how mechanical stimuli recruit characteristic ensembles of transcriptomically defined neurons, providing rules to help explain the discriminatory power of touch. We anticipate a similar approach could expose fundamental principles governing representation of information throughout the nervous system.