Explaining the observed relation between stellar activity and rotation