gpt4 book ai didi

减少文本函数中字母之间的间距

转载 作者:行者123 更新时间:2023-12-02 01:09:56 24 4
gpt4 key购买 nike

当我使用文本函数时,我试图找到一种方法来减少图中字母之间的间距...

par(mar=rep(0,4))
plot.new()
text(0.5,0.8,"text", cex=8)

我希望每个字母之间几乎没有空格,或者重叠选项(如下图底部所示......我在 MS 绘图中手工完成)。

text

最佳答案

这是执行此操作的函数的开始:

   squishtext <- function(x,y, text, squish=1) {
text <- strsplit(text, '')[[1]]
w <- strwidth(text)
ww <- cumsum(c(0,head(w,-1)) * squish)
text( x + ww, y, text, adj=c(0,0) )
}

和一个简单的例子/检查:

    plot(1:10, type='n')
text( 5, 3, "test", adj=c(0,0) )
squishtext( 5, 4, "test", squish=1 )
squishtext( 5, 5, "test", squish=0.8 )
squishtext( 5, 6, "test", squish=0.5 )
squishtext( 5, 7, "test", squish=1.2 )
squishtext( 5, 8, "test", squish=2 )

它可以被扩展以接受额外的参数(adjcex 等)。

关于减少文本函数中字母之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18345196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com