2

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.

tjebo
  • 21,977
  • 7
  • 58
  • 94

2 Answers2

3

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

Duck
  • 39,058
  • 13
  • 42
  • 84
  • 1
    Yes! It actually helped! I found out that doing a double carat "^^" instead of a single also does the job but your solution definitely gives more room to work with. – fernando schuh Jan 15 '21 at 18:27
  • @fernandoschuh why not also offering this as an answer to your own question - this way this solution is better visible and will help future generations :) Thanks for your contribution and welcome to Stackoverflow. Nice first question. – tjebo Jan 15 '21 at 18:46
0

Later on I've found out that we can just use a double carat in the code which also answers my question:

labs(title = "The title of the plot^^21")