To ask the question is to answer it. Those areas are not just any ghettos. Brooklyn and anywhere in NYC, especially close to Manhattan, has the cool factor - urban authenticity (several legendary hip hop stars are from BedStuy, for example) an element of danger, edginess, charm, a very long/rich history, cultural diversity (lots of different races, immigrants from all over the world, etc), eclecticism - all of which appeal to many hipsters, artists, students, young professionals, celebs and other trendsetter types.
And it's not just proximity to people's jobs in Manhattan, because as Vincent stated, even many areas there were industrial slums before they became upscale areas. It has much more to do with the fact that many people don't want to live a bland, conservative, suburban existence even when they have the money to do so.