Scotland has failed to achieve its target of generating the equivalent of 100% of its electricity demand from renewables by 2020 by a short margin.