R Doplot()坐标定位器()

时间:2013-10-31 12:01:42

标签: r plot

我绘制了2个fasta序列的点图(使用seqinr包中的dotPlot()),我需要从图中提取一些值(x,y)。 Dotplot()输出是一个图像 通用的dotplot可能就是这个

enter image description here

我需要例如start&的值。局部对齐的结尾,由紫色线条表示 所以这里有一个例子

l=30
seq1 <- paste(sample(c("A","G","T","C"), l, repl=TRUE)) 
seq2 <- paste(sample(c("A","G","T","C"), l, repl=TRUE)) 

dotPlot(seq1,seq2, wsize = 2, wstep = 1, nmatch = 2, col = c("white", "green"), xlab = deparse(substitute(seq1)), ylab = deparse(substitute(seq2)))

enter image description here

  locator(n=2, type="p")
$x
[1] 27.18720 31.23263

$y
[1] 20.45222 24.65726

所以我想要完全确定2个圆圈点的位置,正如您所看到的, locator() 给出小数值。 我可以使用 ceiling() round() ,但我可能会收到一个近似错误

我需要点击的点的整数值,基本上是距离地点最近的点

使用 identify() 非常适合使用 {{1}} ,它可以使用“普通”图并向您的“点击”返回最接近绘制值的向量,但它不起作用在dotPlot()输出上(问题似乎是它不能作为定位器()在图像输出上工作)

欢迎任何可能的解决方案,包括在shell或python中使用dotter。感谢

2 个答案:

答案 0 :(得分:0)

正如您所提到的,Identify不起作用,因为它需要绘图而不是图像。也许解决方案是在image之后调用plot(type="n",..),但这需要更改dotPlot函数源代码。另一个优雅的解决方案是使用lattice包和panel.identify相当于identify的网格。

这是一个例子,我选择了一些点(6 - > 15):

library(lattice)
dotplot(y~x,data.frame(x=letters,y=letters))
trellis.focus("panel", 1, 1)
> panel.identify()
 [1]  6  7  8  9 10 11 12 13 14 15

enter image description here

答案 1 :(得分:0)

在github上查看evolvedmicrobe/dotplot

https://github.com/evolvedmicrobe/dotplot/blob/master/R/plotters.R

它提供mkDotPlotDataFrame。这样,您可以更好地获取比赛之间的坐标,例如identify