The answer would be the species’ niche. A niche includes all the interactions of a species.
Yes, pH of the soil affects the colour of flower.
Flowering plants grown in acidic soil (pH<7) bears blue flowers or at has a blueish tint.
Whereas, Flowering plants grown in Neutral (pH=7) and Basic (pH>7) soil bears pink and red flowers.
A plant's flower color is determined by a complex balance between chlorophyll, beta carotene, flavonoids,etc in particular pH of the soil to give out vibrant colors like red, blue, pink, yellow,etc.
Heredity is the passing on of traits from parents to their offspring, either through asexual reproduction or sexual reproduction, the offspring cells or organisms acquire the genetic information of their parents.