It's a long trip. I wouldn't sugar coat it.
Bus to Bakersfield
Train to Merced
Bus to yosemite
Plan a day.
I took train from Bakersfield to Merced. It's mirror image of SFO (Richmond) to Merced. Other half of that daily route on San Joaquin. Flying to sfo, is closer and like skipping the bus ride from lax to Bakersfield.
But the worst thing about a day of travel like that is there's no place and nothing to eat. Except what's in your travel pack. You might get a microwave hot dog on the train.