R中的智能点标签放置 [英] Intelligent point label placement in R

查看:111
本文介绍了R中的智能点标签放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)是否有任何R库/函数可以在R图中实现INTELLIGENT标签的放置?我尝试了一些,但是它们都是有问题的-许多标签彼此重叠或与其他点(或绘图中的其他对象重叠),但是我发现这很难处理.

1) Is there any R library/function which would implement INTELLIGENT label placement in R plot? I tried some but they are all problematic - many labels are overlaping either each other or other points (or other objects in the plot, but I see that this is much harder to handle).

2)如果不是,是否有任何方法可以如何在特定问题点上通过标签的放置来舒适地帮助算法?想要最舒适,最有效的解决方案.

2) If not, is there any way how to COMFORTABLY help the algorithm with the label placement for particular problematic points? Most comfortable and efficient solution wanted.

您可以使用我的可复制示例来玩耍并测试其他可能性,并查看您是否能够取得比我更好的结果:

You can play and test other possibilities with my reproducible example and see if you are able to achieve better results than I have:

# data
x = c(0.8846, 1.1554, 0.9317, 0.9703, 0.9053, 0.9454, 1.0146, 0.9012, 
0.9055, 1.3307)
y = c(0.9828, 1.0329, 0.931, 1.3794, 0.9273, 0.9605, 1.0259, 0.9542, 
0.9717, 0.9357)
ShortSci = c("MotAlb", "PruMod", "EriRub", "LusMeg", "PhoOch", "PhoPho", 
"SaxRub", "TurMer", "TurPil", "TurPhi")

# basic plot
plot(x, y, asp=1)
abline(h = 1, col = "green")
abline(v = 1, col = "green")

然后,对于标签,我尝试了这些可能性,没有人真的很不错:

1)这很可怕:

text(x, y, labels = ShortSci, cex= 0.7, offset = 10)

2)如果您不想为所有点都放置标签,而只是为所有点放置标签,则此方法很好 离群值,但仍然经常将标签放置在错误的位置:

2) this one is good if you don't want to place labels for all points, but just for the outliers, but still, the labels are often placed wrong:

identify(x, y, labels = ShortSci, cex = 0.7)

3)这看起来很不合理,但是存在标签与标签之间的距离太近的问题 点我不得不给它们留一些空格,但这并没有太大帮助:

3) this one looked promissing but there is the problem of labels being too close to the points; I had to pad them with spaces but this doesn't help much:

require(maptools)
pointLabel(x, y, labels = paste("  ", ShortSci, "  ", sep=""), cex=0.7)

4)

require(plotrix)
thigmophobe.labels(x, y, labels = ShortSci, cex=0.7, offset=0.5)

5)

require(calibrate)
textxy(x, y, labs=ShortSci, cx=0.7)

提前谢谢!

编辑:要尝试:实验室弯曲{Hmisc} .

推荐答案

我找到了一些解决方案!不幸的是,这不是终极的和理想的,但它现在对我来说是最合适的.这是一半算法,一半手动,因此与joran绘制的纯手动解决方案相比节省了时间.

I found some solution! It's not ultimate and ideal unfortunatelly, but it's the one that works the best for me now. It's half algoritmic, half manual, so it saves time compared to pure manual solution sketched by joran.

我忽略了?identify帮助中非常重要的部分!

I overlooked very important part of the ?identify help!

如果出现以下情况,则用于放置标签的算法与文本所使用的算法相同 pos是在此处指定的,不同之处在于 相对于已识别点的指针确定了pos中的位置.

The algorithm used for placing labels is the same as used by text if pos is specified there, the difference being that the position of the pointer relative the identified point determines pos in identify.

因此,如果您使用我在问题中所写的identify()解决方案,那么您可以通过不直接单击该点,而是通过相对地单击该点旁边的来影响标签的位置朝着想要的方向!!!

So if you use the identify() solution as I wrote in my question, then you can affect the position of the label by not clicking directly on that point, but by clicking next to that point relatively in the desired direction!!! Works just great!

缺点是只有4个位置(上,左,下,右),但我更欣赏其他四个位置(左上,右上,左下,右下). .所以我用它来标记那些不会困扰我的点,以及我在Powerpoint演示文稿中直接标记的其余点,如joran提出的那样:-)

The downside is that there are only 4 positions (top, left, bottom, right), but I'd more appreciate the other 4 (top-left, top-right, bottom-left, bottom-right)... So I use this to labels points where it doesn't bother me and the rest of the points I label directly in my Powerpoint presentation, as joran proposed :-)

P.S .:我还没有尝试过Directlabels格/ggplot解决方案,我仍然更喜欢使用基本的图库.

P.S.: I haven't tried the directlabels lattice/ggplot solution yet, I still prefer to use the basic plot library.

这篇关于R中的智能点标签放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆