wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
650 stars 37 forks source link

lineheight < 1 does not reduce size of linebreaks #96

Open swhalemwo opened 1 year ago

swhalemwo commented 1 year ago

thanks for this great package! While working with it, I noticed that lineheights are not properly scaled when they are smaller than 1.

library(ggplot2)
library(ggtext)
library(gridExtra)

df2 <- data.frame(x=c(1,2), y=c(2,1), 
                  label1 = c("linebreaks\nlinebreaks\nlinebreaks", "linebreaks\nlinebreaks\nlinebreaks"),
                  label2 = c("linebreaks<br>linebreaks<br>linebreaks", "linebreaks<br>linebreaks<br>linebreaks"))

## small linebreaks work in geom_label
p1 <- ggplot(df2, aes(x=x, y=y)) +
    geom_label(aes(label = label1), lineheight = 0.3) +
    xlim(0, 3) + ylim(0,3)

## small linebreaks don't work properly in geom_richtext
p2 <- ggplot(df2, aes(x=x, y=y)) +
    geom_richtext(aes(label = label2), lineheight = 0.3) +
    xlim(0, 3) + ylim(0,3)

## larger linebreaks work properly 
p3 <- ggplot(df2, aes(x=x, y=y)) +
    geom_richtext(aes(label = label2), lineheight = 3) +
    xlim(0, 3) + ylim(0,3)

grid.arrange(p1,p2,p3)

Created on 2022-09-28 with reprex v2.0.2