Hi,
When I plot text and use cex to change the text size, I notice that the cex
multiplier is not exact. It looks as if the real size of text can take only
certain discrete values. Is there a workaround to get text to follow the cex
value more closely, or at least to be able to figure out what the real cex value
will be?
Here is an example that illustrates the problem:
cex <- seq(0.5, 1, 0.01)
x <- 0.05
y <- (1:length(cex))/length(cex)
labels <- paste("XXXXXX", cex)
plot.new()
text(x=x, y=y, labels=labels, pos=4, cex=cex)
/Ali
cex multiplier not exact
4 messages · Ali Tofigh, Uwe Ligges, Brian Ripley
On 23.10.2011 22:33, Ali Tofigh wrote:
Hi, When I plot text and use cex to change the text size, I notice that the cex multiplier is not exact. It looks as if the real size of text can take only certain discrete values. Is there a workaround to get text to follow the cex value more closely, or at least to be able to figure out what the real cex value will be?
Typically this is multiplied by the default pointsize of the current device and rounded to an integer - the resulting pointsize that you see with your code. If you want to know it absolute precisely: This may even depend on the device and I think you will have to read the source code in order to find out how it is actually implemented for your current device (which you have not even stated). Uwe Ligges
Here is an example that illustrates the problem:
cex<- seq(0.5, 1, 0.01)
x<- 0.05
y<- (1:length(cex))/length(cex)
labels<- paste("XXXXXX", cex)
plot.new()
text(x=x, y=y, labels=labels, pos=4, cex=cex)
/Ali
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On Mon, 24 Oct 2011, Uwe Ligges wrote:
On 23.10.2011 22:33, Ali Tofigh wrote:
Hi, When I plot text and use cex to change the text size, I notice that the cex multiplier is not exact. It looks as if the real size of text can take only certain discrete values. Is there a workaround to get text to follow the cex value more closely, or at least to be able to figure out what the real cex value will be?
Typically this is multiplied by the default pointsize of the current device and rounded to an integer - the resulting pointsize that you see with your code. If you want to know it absolute precisely: This may even depend on the device and I think you will have to read the source code in order to find out how it is actually implemented for your current device (which you have not even stated).
It may be in the help for that unstated device (the help for windows() says that it is rounded to bigpoints), and in some cases the rounding is in the OS services (it is for the X11() device, for example) and hence very hard to know precisely. Oh, and the cex for text and for symbols (pch = 0:25) may not work the same way.
Uwe Ligges
Here is an example that illustrates the problem:
cex<- seq(0.5, 1, 0.01)
x<- 0.05
y<- (1:length(cex))/length(cex)
labels<- paste("XXXXXX", cex)
plot.new()
text(x=x, y=y, labels=labels, pos=4, cex=cex)
/Ali
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Mon, Oct 24, 2011 at 06:10, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
On Mon, 24 Oct 2011, Uwe Ligges wrote:
On 23.10.2011 22:33, Ali Tofigh wrote:
Hi, When I plot text and use cex to change the text size, I notice that the cex multiplier is not exact. It looks as if the real size of text can take only certain discrete values. Is there a workaround to get text to follow the cex value more closely, or at least to be able to figure out what the real cex value will be?
Typically this is multiplied by the default pointsize of the current device and rounded to an integer - the resulting pointsize that you see with your code. If you want to know it absolute precisely: This may even depend on the device and I think you will have to read the source code in order to find out how it is actually implemented for your current device (which you have not even stated).
It may be in the help for that unstated device (the help for windows() says that it is rounded to bigpoints), and in some cases the rounding is in the OS services (it is for the X11() device, for example) and hence very hard to know precisely.
I was hoping to write code that would work on most devices. I'm trying to write a function that plots and automatically adjusts the size of a given text string to fit inside an predefined area (actually a viewport from the grid package). I try to do this by computing the width and height of the text using the unit function: unit(1, "strwidth", x) and unit(1, "strheight, x").
From these values I then compute the desired cex value. But from the
information you and Uwe provided, I'm beginning to think that such a function might not be feasible at all? Thank you for all the info, Best wishes /Ali
Oh, and the cex for text and for symbols (pch = 0:25) may not work the same way.
Uwe Ligges
Here is an example that illustrates the problem:
cex<- seq(0.5, 1, 0.01)
x<- 0.05
y<- (1:length(cex))/length(cex)
labels<- paste("XXXXXX", cex)
plot.new()
text(x=x, y=y, labels=labels, pos=4, cex=cex)
/Ali
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Brian D. Ripley, ? ? ? ? ? ? ? ? ?ripley at stats.ox.ac.uk Professor of Applied Statistics, ?http://www.stats.ox.ac.uk/~ripley/ University of Oxford, ? ? ? ? ? ? Tel: ?+44 1865 272861 (self) 1 South Parks Road, ? ? ? ? ? ? ? ? ? ? +44 1865 272866 (PA) Oxford OX1 3TG, UK ? ? ? ? ? ? ? ?Fax: ?+44 1865 272595