Ranged then branches into guns or bows, melee into horse or infantry- again, nothing to stop you from mixing and matching equipment but check which factions have what troops as their 'Hamato guard'- these are the very top of the troop tree and have the best equipment. Once you become a samurai you start at the bottom of the tree and decide early on if you want to be ranged or melee. This option will also appear after getting to the Elite level- check on the wiki which faction has elite skirmishers or spearmen, because you need to select the right troop tree. Don't forget to change the equipment given to you by the faction for better stuff you've looted! After a certain amount of renown (about 300? 400?) You can talk to your commander to change from Ashigaru to Samurai.
After a while you and him will be best friends. Also, after every siege battle you do, talk to your commander, as your relations will go up by 2. Once you decide to go ranged or melee you can't change what ashigaru when you go up the ranks, even if you quit and join another lord (I suggest melee because you can just loot a bow and you get better armour I think). You'll start as an ashigaru, which is fine just remember to tweak your equipment so you're not such Stuck with a weapon you don't know how to use. As usual with freelancing, the faction leaders are probably the best as they won't get defeated as much (I've had fun with the Dante and Shimazu).