问题描述
|
我想使图上的文本不完整,以避免过度绘图。为此,我假设我需要一个围绕文本组件的边框。有办法吗?
例如,在基本图形中:
plot.new()
text(.5,.5,\"word\")
text(.6,\"word\") #does this overlap?
在网格中,有一种方法可以删除重叠的文本,但是我似乎找不到一种方法来访问确定是否发生重叠的代码。
grid.text(c(\"word\",\"other word\"),c(.5,.6),.5),check=T)
解决方法
strwidth
和strheight
功能可能在这里有帮助
stroverlap <- function(x1,y1,s1,x2,y2,s2) {
sh1 <- strheight(s1)
sw1 <- strwidth(s1)
sh2 <- strheight(s2)
sw2 <- strwidth(s2)
overlap <- FALSE
if (x1<x2)
overlap <- x1 + sw1 > x2
else
overlap <- x2 + sw2 > x1
if (y1<y2)
overlap <- overlap && (y1 +sh1>y2)
else
overlap <- overlap && (y2+sh2>y1)
return(overlap)
}
stroverlap(.5,.5,\"word\",.6,\"word\")
, 包maptools
具有称为pointLabel
的功能。
使用优化例程找到好的
没有标签的点标签的位置
重叠。
, 如果您使用的是基本图形,那就是thigmophobe {plotrix}
\“找到远离最近点的方向\”
使用格,Harrell提供了:
labcurve {Hmisc}
\“标记曲线,制作关键点以及交互式绘制点和曲线\”