简体   繁体   中英

labelling specific data points in graph R without ggplot

I am trying to label the data points which are shaded in the plot. 在此处输入图像描述

Here is my sample data:

    genes     logFC       PValue
1 Arhgap8 -5.492152 2.479473e-99
2    Asns -2.519970 2.731718e-93
3    Bmp4 -1.663583 4.767201e-72
4   Casp1 -1.650139 2.212689e-25
5    Ctgf -1.272772 1.000103e-61
6    Eya4 -2.328052 2.077364e-68

my plot code till now:

plot(sample$logFC,-log10(as.numeric(sample$PValue)),pch = 20,xlab = 'Log2 FoldChange',ylab = '-Log10 p-value',col = 'blue',xlim = c(-10,8),ylim = c(0,300),cex.lab=1.5, cex.axis=1.5)
points(sample$logFC,-log10(as.numeric(sample$PValue)),col = "dark green")
with(subset(sample,genes=='Arhgap8'),points(logFC,-log10(as.numeric(PValue)),pch = 20, col="orange"))

I have tried using the below command including text;but it doesnt show me the label.

with(subset(sample,genes=='Arhgap8'),points(logFC,-log10(as.numeric(PValue)),pch = 20, col="violet"),text(sample,labels = sample$genes,cex = 0.9,pos = 4))

The correct way to use with to run to commands would be

with(subset(sample, genes=='Arhgap8'), { 
  points(logFC, -log10(as.numeric(PValue)), pch = 20, col="violet")
  text(logFC, -log10(as.numeric(PValue)), labels = genes, cex = 0.9, pos = 4)
})

When you pass more arguments with with() , they are silently ignored. For example

with(iris, mean(Sepal.Length), stop("not run"))

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