Gene expression levels in clonal bacterial groups have been found to be spatially correlated. These correlations can partly be explained by the shared lineage history of nearby cells, although they could also arise from local cell-cell interactions. Here, we present a quantitative framework that allows us to disentangle the contributions of lineage history, long-range spatial gradients, and local cell-cell interactions to spatial correlations in gene expression. We study pathways involved in toxin production, SOS stress response, and metabolism in Escherichia coli microcolonies and find for all pathways that shared lineage history is the main cause of spatial correlations in gene expression levels. However, long-range spatial gradients and local cell-cell interactions also contributed to spatial correlations in SOS response, amino acid biosynthesis, and overall metabolic activity. Together, our data show that the phenotype of a cell is influenced by its lineage history and population context, raising the question of whether bacteria can arrange their activities in space to perform functions they cannot achieve alone.