You have to study composition to understand that things can be done backwards and forwards and upside down, inverted, but it's mainly just an inner valid intuitive thing. Where do you want to go? Ok this is busy, or this needs some space, or this is too much space so now I want to put more notes in there or something. It's all about contrast. High, low. Fast, slow, thick or thin or what have you. And it's the same with improvisation.