rggplot2

Using the ceiling symbol (⌈ ⌉) in ggplot facet labels


An example code is shown below, but I cannot remove the word 'expression' and the parentheses (). I would like to remove them. An entirely different way to accomplish the same thing (i.e., showing the ceiling symbol in the panel label) is also acceptable.

library(ggplot2)
library(latex2exp)


df_test <- data.frame(
  x = 1:2,
  y = 1:2,
  group_original = c("ABC", "DEF") 
)

final_facet_labels_expressions <- list(
  "ABC" = TeX("$qqq+\\lceil T_{ABC} \\rceil$"),
  "DEF" = TeX("$qqq+\\lceil T_{DEF} \\rceil$")
)


df_test$group <- factor(df_test$group_original,
                        levels = names(final_facet_labels_expressions), 
                        labels = final_facet_labels_expressions)     


ggplot(df_test, aes(x, y)) +
  geom_point() +
  facet_wrap(~ group, labeller = labeller(group = label_parsed)) +
  theme_bw()

enter image description here


Solution

  • library(ggplot2)
    library(latex2exp)
    
    
    custom_labeller <- function(labels) {
      tex_expressions <- list(
        "ABC" = TeX("$qqq+\\lceil T_{ABC} \\rceil$"),
        "DEF" = TeX("$qqq+\\lceil T_{DEF} \\rceil$")
      )
      result <- lapply(labels, function(x) {
        lapply(x, function(level) tex_expressions[[level]])
      })
      
      return(result)
    }
    
    ggplot(df_test, aes(x, y)) +
      geom_point() +
      facet_wrap(~ group_original, labeller = custom_labeller) +
      theme_bw()
    

    Created on 2025-07-31 with reprex v2.1.1