在没有ggplot的情况下标记图R中的特定数据点

时间:2019-11-06 19:18:23

标签: r plot scatter-plot

我正在尝试标记图中阴影部分的数据点。enter image description here

这是我的示例数据:

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

直到现在我的情节代码:

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

我尝试使用下面的命令(包括文本);但是它没有显示标签。

index_by

1 个答案:

答案 0 :(得分:1)

使用with运行命令的正确方法是

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

当您使用with()传递更多参数时,它们将被静默忽略。例如

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