For many New Yorkers, their subway line is a second home. They see their neighbors on the same route; they know which car will be closest to their exit; and they have favorite spots for the ride. Mr. Wagner, who has been taking photographs in the subway since 2013 and whose book, “Here for the Ride,” will be published this week, likes to stand in front of the doors. “I can see everything in the car that way,” he said.

With a background in social work, he was interested in capturing acts of kindness, among other things, in the confined spaces. “I wanted to witness those acts of humanity happening in this very public space,” he said. “People giving up their seats to a mother and child or helping hold the door for someone running to catch the train.”

Of the two young women above, Mr. Wagner said: “It took me right back to my childhood with my friends, trying to figure out how to get our hair together. It made me think about black culture and friendship.”