From the LA Union Station take the LA Metrolink commuter train service to Lancaster ($10.50).
From Lancaster, board the Kern Regional Transit Authority's (KRTA) "East Kern Express" bus to Mojave ($2.00).
In Mojave, you'll transfer to KRTA "Ridgecrest Service" (Mon, Wed, & Fri. only) and ride it all the way out to Ridgecrest ($4.00).
There, you'll transfer to the Carson Ridgecrest Eastern Seirra Transit (CREST) Bus from Ridgecrest to Mammoth ($21.00)(Mon, Wed, & Fri. only).
From Mammoth, take Yosemite Area Regional Transportation System (YARTS) Highway 120 bus to Yosemite Valley (Hwy 140 closed Winter) ($15).
Transfer to YARTS Highway 140 Bus to Merced ($12.50) and ride it to Merced Transportation Center.
Transfer to Stanislaus Regional Transit (StaRT) Route 70 bus ($2.00 + 0.25 transfer) to the Modesto Transit Center.
Transfer to the Modesto Area Express (MAX) bus 41 to Vintage Faire Mall.
From Vintage Fair Mall, catch the early morning "Modesto ACE Express" bus ($2.00), which connects to the ACE commuter rail trains at the Lathrop/Manteca station.
Buy a ticket on ACE to Pleasanton ($7.50), where you will transfer to Livermore Amador Valley Transit Authority (LAVTA) bus 54 to the Dublin Bay Area Rapid Transit (BART) Station ($1.50).
From Dublin, you can ride the BART Blue Line to a variety of places in San Francisco from the Embarcadero to SFO Airport ($4.95-7.35)
Mind you, this routing won't really work unless you factor in overnight stays at several points along the way due to the mismatches of the schedules. I haven't tried to work it out myself, but at a rough guess I expect at least two overnights would be involved, maybe three. Not to mention that just the accumulated fares are more than the cost of a one-way ticket on Southwest Airlines.
This does remind me that during the glory days of the interurban railways, it was said to be at least theoretically possible to travel from Chicago to New York City totally by interurban, without resort to the "steam railway." Except that, just like the routing above, you couldn't do it without spending the night somewhere, be it a hotel or a lonely interurban stop.