The Upper Berth is a short story from circa 1886 by Francis Marion Crawford. It can be read online.
The Literary Gothic says it is "Perhaps overly anthologized, but this is classic ghostly Crawford." The Nostalgis League says,
Crawford's life of travel served him well when penning this story; the many little details of ship life and the asides of the seasoned sea-traveler who narrates the story have the casual but concrete ring of reality—which makes the unreal and horrifying discovery of the Upper Berth's inhabitant all more startling when it comes.