控制字体粗细而不改变字体大小
我正在寻找一种方法来控制在 R 中绘制的文本的线条粗细,而不改变字符的尺寸。这是一个示例(不使用 R
):
中间单词的粗细为顶部的两倍,但尺寸相同(因此没有发生缩放)。底部的单词实际上是两个单词:一个红色单词覆盖在一个沉重的白色单词上,以创建颜色分离(对于注释繁忙的情节特别有用)。
这是我组合在一起尝试复制上图的一组命令:
png("font.png",width=1.02, height=1.02, units="in", res=150)
par(ps=10, font=1, bg="light gray", col="black", mai=rep(0.02,4), pin=c(1,1))
plot.new()
box()
text(0.5,0.85,"FONT",cex=1)
text(0.5,0.6,"FONT",cex=2)
text(0.5,0.3,"FONT",cex=2,col="white")
text(0.5,0.3,"FONT",cex=1,col="red")
text(0.5,0.1,"FONT",cex=1, font=2, col="white")
text(0.5,0.1,"FONT",cex=1, font=1, col="red")
dev.off()
给出:
所以效果是与将 font-face 更改为粗体相同,但大小差异不足以在重叠时明显注意到。 par
帮助页面似乎没有这方面的具体设置。有人有什么想法吗?
请注意,在我上次检查时,更改 ggplot2
中的 size
也不会产生我想要的效果。
I'm looking for a way to control the line thickness of text plotted in R
without having the dimensions of the characters change. Here's an example (not using R
):
The middle word has a thickness of twice the top, yet the dimensions are the same (so no scaling happened). The bottom word is actually two words: a red word overlain on a heavy white word, to create color separation (especially useful for annotating a busy plot).
Here's a set of commands I threw together to try and replicate the figure above:
png("font.png",width=1.02, height=1.02, units="in", res=150)
par(ps=10, font=1, bg="light gray", col="black", mai=rep(0.02,4), pin=c(1,1))
plot.new()
box()
text(0.5,0.85,"FONT",cex=1)
text(0.5,0.6,"FONT",cex=2)
text(0.5,0.3,"FONT",cex=2,col="white")
text(0.5,0.3,"FONT",cex=1,col="red")
text(0.5,0.1,"FONT",cex=1, font=2, col="white")
text(0.5,0.1,"FONT",cex=1, font=1, col="red")
dev.off()
giving:
So the effect is the same as changing the font-face to bold, but the size difference is not big enough to be noticeable when overlain. The par
help page doesn't appear to have a specific setting for this. Anyone have any ideas?
Note changing size
in ggplot2
doesn't produce the effect I want either, last time I checked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试添加以圆形图案稍微移动的多个版本的文本,
有一个使用隐藏在中的基本图形的版本R-help 的档案,这是受到启发的。
You could try adding multiple versions of the text slightly shifted in a circular pattern,
There's a version using base graphics lurking in the archives of R-help, from which this is inspired.
另一种选择是使用临时 postscript 文件,通过
grImport
转换为形状,我想可以使用临时光栅图形文件来完成类似的操作,通过某种图像处理算法进行模糊处理并在文本下方显示为光栅。
Another option using a temporary postscript file, converted to a shape by
grImport
,I imagine something similar could be done with a temporary raster graphic file, blurred by some image processing algorithm and displayed as raster below the text.
你可以尝试:
虽然我不确定你会如何做第三个版本的 FONT。
You could try:
Although I'm not sure how you'd do the third version of FONT.