繁体   English   中英

有人知道 function 以避免点标签在 R 中重叠吗?

[英]Does anybody know a function to avoid point labels to overlap in R?

三元图你好。 有人知道如何使用 PLOTRIX 的 thigmophobe.labels 吗? 或任何其他使点标签无效的 function? 我正在尝试用沉积物数据制作三元图,但我遇到了这个问题,我不知道如何解决它。 一些点标签重叠。 也许这很简单,但我是一个新的 R 用户......

这是代码的一个例子。

library ('rysgran')
data (camargo2001)

class.percent (camargo2001, mode="total")
percent <- class.percent(camargo2001, mode="total")
x<-percent[2:4]
rysgran.ternary(x, method = "pejrup", lang = "e", main="",
                show.labels=FALSE, label.points=TRUE, axis.labels = NULL, show.names = TRUE,
                cex.labels= 1, cex.points=0.9, show.legend=FALSE,
                cex.axis=1, cex.names = 0.8, col.names = "blue", col = "blue",
                col.labels= "black", col.axis= "black", col.lines= "black",
                pch = 16, lty.grid = 10, pos=3)

这将是困难的,因为这些点都聚集在左下角。 此外, thigamaphobe.labels中的plotrix等辅助函数(以及该函数手册页中提到的其他函数)需要知道该点的坐标,但rysgran.ternary不返回该信息。 Some of the other ternary plot functions do or provide a function to convert the 3d coordinates to 2d plot coordinates.

鉴于此,您可以通过以下一些方法来解决问题:

  1. 如果您要打印到打印设备,请将 plot 放大,以免重叠严重。 当我重新创建您的 plot 并将 window 拖得更大时,许多重叠消失了。

  2. cex.labels=更改为更小的值,例如 0.8。 这将使标签更小。

  3. 使用pos=c(3, 2, 1, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3)重新定位标签。 这告诉 R plot label 相对于点的位置,1-below,2-left,3-above,4-right。 目前,您正在使用 3 在该点上方绘制所有标签。

  4. 更多的工作,但更多的控制。 不要自动 plot 标签。 生成 plot 然后使用pt <- locator()并单击图形上的点以获取其 plot 坐标。 将此信息与points()一起使用到 plot 的标签正是您想要的位置。 保存坐标,这样每当您重新生成 plot 时,您就已经计算出坐标。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM