shome
shome

Reputation: 1402

labelling specific data points in graph R without ggplot

I am trying to label the data points which are shaded in the plot.enter image description here

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))

Upvotes: 0

Views: 92

Answers (1)

MrFlick
MrFlick

Reputation: 206197

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"))

Upvotes: 1

Related Questions