[英]finding the bounding box of plotted text
I would like to jitter the text on a plot so as to avoid overplotting.我想在 plot 上抖动文本以避免过度绘制。 To do so, I assume that I need a bounding box around the text component.为此,我假设我需要一个围绕文本组件的边界框。 Is there a way to get this?有没有办法得到这个?
For example, in base graphics:例如,在基本图形中:
plot.new()
text(.5,.5,"word")
text(.6,.5,"word") #does this overlap?
In grid there is a way to drop overlapping text, but I can't seem to find a way to access the code that figures out if overlapping has occurred.在网格中有一种方法可以删除重叠的文本,但我似乎无法找到一种方法来访问确定是否发生重叠的代码。
grid.text(c("word","other word"),c(.5,.6),c(.5,.5),check=T)
Maybe the strwidth
and strheight
functions can help here也许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,.5, "word")
If you were using base graphics it would be thigmophobe {plotrix}如果您使用的是基本图形,它将是 thigmophobe {plotrix}
"Find the direction away from the closest point" “寻找远离最近点的方向”
Using lattice, Harrell has offered:使用 lattice,Harrell 提供了:
labcurve {Hmisc} labcurve {Hmisc}
"Label Curves, Make Keys, and Interactively Draw Points and Curves" “标注曲线、制作关键点以及交互式绘制点和曲线”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.