Home > database >  Overline in ggplot axis label
Overline in ggplot axis label

Time:06-08

I'm trying to create some ggplot with overlined axis title. Using a reproducible example, my code is:

library(ggplot2)
library(ggtext)

data("iris")

ggplot(iris, aes(Sepal.Length, Sepal.Width))  
  geom_point()  
  xlab("<span style = 'text-decoration: overline;'>Sepal</span> <span style = 'color: #00e000;'>Length</span>")  
  theme(axis.title.x = element_markdown())

The result, however, doesn't work as expected (overline missing on "Sepal"):

image1

CodePudding user response:

If you don't mind losing the color, you can do it using plotmath methods:

library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width))  
  geom_point()  
  xlab(expression(paste(over(,"Sepal"), atop(," Length"))))

Created on 2022-06-07 by the enter image description here

  • Related