Modify the legend code image to a block colour related to the geology code

How do you modify the legend code image to a block colour related to the geology code?