简体   繁体   中英

How do I label the points of my scatterplot in R?

I have a data frame containing ~10000 rows and 3 columns:

ENSEMBL            J1.1     J1.2
ENSG00000166710    800      900
ENSG00000163220    15000    32500
ENSG00000156508    600      900
...

> as.data.frame(colnames(TPMProtCod_J1.1_J1.2))
  colnames(TPMProtCod_J1.1_J1.2)
1                        ENSEMBL
2                           J1.1
3                           J1.2
> dim(TPMProtCod_J1.1_J1.2)
[1] 10602     3

I've created a scatterplot with the following code:

plot(TPMProtCod_J1.1_J1.2$J1.1, TPMProtCod_J1.1_J1.2$J1.2, col = "lightblue", pch=19, cex=2, xlab = "J1.1 (TPM)", ylab = "J1.2 (TPM)")
text(TPMProtCod_J1.1_J1.2$J1.1, TPMProtCod_J1.1_J1.2$J1.2, labels = row.names(TPMProtCod_J1.1_J1.2), cex= 0.9)

在此处输入图像描述

But how do I make it so that each point displays the corresponding ensembl ID instead of the row number?

It seems that you need to change row.names(...) to TPMProtCod_J1.1_J1.2$ENSEMBL :

text(TPMProtCod_J1.1_J1.2$J1.1, TPMProtCod_J1.1_J1.2$J1.2, labels = TPMProtCod_J1.1_J1.2$ENSEMBL, cex= 0.9)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM