Search code examples
rggplot2formatmarkdownggtext

Reduce superscript font size ggplot2 R


I'm developing a script with ggplot2 and the package ggtext to produce some plots with superscripts next to the title that further are grouped in a reference table.

A simplified example of what I'm doing is:

library(ggplot2)
library(ggtext)

ggplot() +
geom_blank() +
labs(title = "The title of the plot^21") +
theme_void() +
theme(plot.title = element_markdown(size = 20, hjust = 0.5))

But as I need to work with big font sizes in my project, it just happens that the superscript font size is too big. Is there a way to reduce it while keeping the same text size? Thank you in advance.


Solution

  • Maybe this can be helpful:

    library(ggplot2)
    library(ggtext)
    #Code
    ggplot() +
      geom_blank() +
      labs(title = "The title of the plot<span style='font-size:20pt;
           color:black'><sup>2</sup></span>") +
      theme_void() +
      theme(plot.title = element_markdown(size = 25, hjust = 0.5))
    

    Output:

    enter image description here