从Label中绘制线到R中的点

时间:2015-05-15 01:04:14

标签: r lines labels

我目前正在尝试生成一个自动脚本来创建标记的折线图。此线图将具有1个或更多个最大值,如果它们高于某个阈值,则必须标记。 目前我可以标记最大值。

https://drive.google.com/file/d/0B50V8cCfhJDQWF94SG85NXVZY1k/view?usp=sharing

为此我在校准包中使用textxy()

然而,当出现多个峰值时,事情变得更加复杂:

https://drive.google.com/file/d/0B50V8cCfhJDQUmF5VERhUV8zNmc/view?usp=sharing

很快就很难看到标签的分配位置。所以我想要的是从标签到峰顶(或下面)的一条线。

今天我一整天都没看好运。我在Intelligent point label placement in R

中尝试了所有内容

wordcloud,但不幸的是,它不允许您偏移标签,如果您只有一个标签,则会失败。

识别,太慢了。我需要能够自动执行此操作,以便每天拍摄数千张图像。

pointLabel,thigmophobe.labels都没有工作,因为他们没有划线,而且我还没有处理很多标签。

我还尝试在标签和点之间手动绘制箭头,但这非常耗时。

有没有人知道任何包装或简单方法吗?这不可能自动化吗?

谢谢! 卡梅伦

1 个答案:

答案 0 :(得分:3)

您可以尝试labelPeaks包提供的MALDIquant功能。其放置峰标签的算法取自Ian Fellows'wordcloud::wordlayout

library("MALDIquant")

data("fiedler2009subset")

## a simplified preprocessing to provide some example data
s <- trim(fiedler2009subset[[1]], c(3000, 3500))
r <- removeBaseline(s)
p <- detectPeaks(r)

## plot the peaks and label them
plot(p, ylim=c(0, 30000))
labelPeaks(p, avoidOverlap=TRUE, underline=FALSE, digits=1)

enter image description here

## rotate labels by 90 degree
plot(p, ylim=c(0, 30000))
labelPeaks(p, underline=FALSE, srt=90, adj=c(0, 0.5), col="red")

enter image description here

## label peaks above 5000
plot(p, ylim=c(0, 30000))
labelPeaks(p, index=intensity(p) > 5000)

enter image description here

有关详细信息,请参阅?labelPeaks