Mike Feigin Mike Feigin - 6 months ago 62
R Question

Adding labels to a scatterplot

I have a dataframe called PSCfull1 with 3 columns: Gene, OrganoidCM, ControlCM. "Gene" is a list of genes, and the other 2 columns have numerical values. I made a scatterplot with:

ggplot(PSCfull1, aes(x=OrganoidCM, y=ControlCM))+geom_point(size=2, shape=16)+geom_text(label=rownames(PSCfull1))

It looks great, but the labels are numbers instead of the names of the genes from column 1. How can I get the labels to be names rather than row numbers? Thanks!


You should tell ggplot that the labels are held in your Gene column:

ggplot(PSCfull1, aes(x = OrganoidCM, y = ControlCM, label = Gene)) +
     geom_point(size=2, shape=16) +