I am travelling to Ibiza via London. I hold an Indian passport. The time difference between my flight from London to Ibiza is around 4 hours. Will I need a transit visa?
Ibiza is a part of the Schengen Area so I presume you have a valid Schengen Visa. What matters more though is what type of Schengen visa it is? Are you traveling for business or tourism or studies?
So, according to a simple tool found on the UK Government Website, putting in your situation i.e the fact that you are an Indian Citizen and you will be coming to the UK only for transit and will not be passing border control, you will need a Direct Airside Transit Visa (DATV) unless you have a Category 'D' Schengen visa or residence permit for a state valid in the European Economic Area (EEA).
Now, even though Spain is a member of the EEA, you must make sure you have the specific visa, which typically includes Residence Permits, Study and other long stay visas. If not, then you will need a DATV.