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

Viewed 69

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. 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.

For characters, get height and width with:
par("cin") inches
par("cra") pixels
par("cxy") xy coordinates

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.)

1 Answers

Through trial and error, it looks like the point diameter (in xy coordinates) is the character height divided by 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")
Related