lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

`geom_text`: too small label size when applied log10 transformation

Open ASmirnov-HORIS opened this issue 1 year ago • 2 comments

Example:

ggplot({'v': [1e10]}, aes(x='v')) + \
    geom_point(aes(size='v'), y=0) + \
    geom_text(aes(label='v'), y=1, size=10) + \
    scale_size(trans='sqrt')

Output:

Expected (like in ggplot2):

ASmirnov-HORIS avatar Dec 18 '24 11:12 ASmirnov-HORIS

Since size=10 in geom_text() the size scale does not affect size of the text regardless of trans.

Is this issue about a difference in interpretation of size in lets-plot vs ggplot2? In lets-plot geom_text size is in px (doubled). I.e. 20 px in this case. In ggplot2 it might be pt or other units.

Please clarify.

alshan avatar Dec 30 '24 18:12 alshan

No, the issue has nothing to do with units. It is precisely that trans should not affect the constant size.

In lets-plot, removing trans changes the plot:

gggrid([
    ggplot({'v': [1e10]}, aes(x='v')) + \
        geom_point(aes(size='v'), y=0) + \
        geom_text(aes(label='v'), y=1, size=10) + \
        scale_size(trans='sqrt', guide='none'),
    ggplot({'v': [1e10]}, aes(x='v')) + \
        geom_point(aes(size='v'), y=0) + \
        geom_text(aes(label='v'), y=1, size=10) + \
        scale_size(guide='none'),
])

In ggplot2 it doesn't:

library(ggplot2)
library(cowplot)

plot_grid(
    ggplot(data.frame(v = c(1e10)), aes(x = v)) +
        geom_point(aes(size = v), y = 0) +
        geom_text(aes(label = v), y = 1, size = 10) +
        scale_size(trans = "sqrt", guide = "none"),
    ggplot(data.frame(v = c(1e10)), aes(x = v)) +
        geom_point(aes(size = v), y = 0) +
        geom_text(aes(label = v), y = 1, size = 10) +
        scale_size(guide = "none")
)

ASmirnov-HORIS avatar Jan 09 '25 10:01 ASmirnov-HORIS