How to underline text in a plot title or label? (ggplot2)

前端 未结 1 1222
眼角桃花
眼角桃花 2020-12-20 12:37

Please pardon my ignorance if this is a simple question, but I can\'t seem to figure out how to underline any part of a plot title. I\'m using ggplot2.

相关标签:
1条回答
  • 2020-12-20 13:21

    Try this:

    ggplot(df, aes(x = x, y = y)) + geom_point() +
      ggtitle(expression(paste("Oh how I wish for ", underline(underlining))))
    

    Alternatively, as BondedDust points out in the comments, you can avoid the paste() call entirely, but watch out for the for:

    ggplot(df, aes(x = x, y = y)) + geom_point() +
      ggtitle(expression(Oh~how~I~wish~'for'~underline(underlining)))
    

    Or another, even shorter approach suggested by baptiste that doesn't use expression, paste(), or the many tildes:

    ggplot(df, aes(x = x, y = y)) + geom_point() +
      ggtitle(~"Oh how I wish for "*underline(underlining))
    
    0 讨论(0)
提交回复
热议问题