简体   繁体   English

将点 cex 转换为英寸、像素或 r 中的 plot 坐标

[英]convert point cex to inches, pixels, or plot coordinates in r

I am trying to convert the point size in cex to units of width and height on the plot. I can work with the units in inches, or pixels, or xy coordinates.我正在尝试将 cex 中的点大小转换为 plot 上的宽度和高度单位。我可以使用以英寸、像素或 xy 坐标为单位的单位。 I found something similar for finding the size of characters, but I can't find anything for plotted points.我发现了一些类似的东西来寻找字符的大小,但我找不到任何关于标绘点的东西。 If I can figure out the size of a point when cex = 1 using par() , then I can calculate the sizes of differently scaled points too.如果我可以使用par()算出cex = 1时点的大小,那么我也可以计算不同比例点的大小。

For characters, get height and width with:对于字符,获取高度和宽度:
par("cin") inches par("cin")英寸
par("cra") pixels par("cra")像素
par("cxy") xy coordinates par("cxy") xy 坐标

Are there similar options to get the sizes of points?是否有类似的选项来获取点的大小?
OR, how do you convert character height and width into point diameter?或者,如何将字符高度和宽度转换为点直径?

(Note that this similar question How to determine symbol size in x and y units only answers for characters and not for points.) (请注意,这个类似的问题How to determine symbol size in x and y units只回答字符而不是点。)

Through trial and error, it looks like the point diameter (in xy coordinates) is the character height divided by 2*pi.通过反复试验,看起来点直径(在 xy 坐标中)是字符高度除以 2*pi。

char.height <- par("cxy")[2]
point.diam <- char.height / (2 * pi)
point.cex <- 7 # try changing and it still works
point.diam.cex <- point.diam * point.cex

plot(x = 0, y = 1, type = "n")
points(x = 0, y = 1, cex = point.cex, pch = 21, bg = "grey")
segments(x0 = 0 - (point.diam.cex/2), x1 = 0 + (point.diam.cex/2), y0 = 1, y1 = 1, col = "red")

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

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