Question Details

No question body available.

Tags

r ggplot2 plot facet ggtext

Answers (1)

Accepted Answer Available
Accepted Answer
March 25, 2026 Score: 2 Rep: 12,638 Quality: High Completeness: 100%

It's a bit hacky, but you could insert spaces using

  • = " "
  • xxxxxxxx = " " (8 spaces)

and after "APOE ε* effects" insert a line break via
and just print "Lower Levels Higher Levels".

Carriercomparison = recode(
    Carriercomparison,
    "e2vse3" = "APOE ε2 effects
Lower Levels xxxxxxxx Higher Levels", "e4vse3" = "APOE ε4 effects
Lower Levels xxxxxxxx Higher Levels" )

res

Add: "Lower Levels" appears with no space

Reading through this

that RStudio graphics device has moved to using systemfonts, and systemfonts doesn't report a width for spaces, it only reports an xadvance value.

This seems to be connected to the rendering engine and also the font supplied in element
markdown - specifically with family = "Arial".

Comic Sans works just fine. Consider extrafont/showtext for a fix or use Lower Levels

strip.text = elementmarkdown(size = 16, color = "black", hjust = 0.5, vjust = 3.5, margin = margin(t = 12, b = 10), family = "Comic Sans MS")

full code

library(ggplot2)
library(dplyr)
library(ggtext)

remotes::installgithub("wilkelab/gridtext")

devtools::installgithub("NightingaleHealth/ggforestplot")

library(ggforestplot)

forest
plotAPOEdata % mutate( Ancestry = factor(Ancestry), Carriercomparison = recode( Carriercomparison, "e2vse3" = "APOE ε2 effects
Lower Levels xxxxxxxx Higher Levels", "e4vse3" = "APOE ε4 effects
Lower Levels xxxxxxxx Higher Levels" ), QMPtrenduncorrected = suppressWarnings(as.numeric(naif(as.character(QMPtrenduncorrected), "NA"))), QMPtrenduncorrectedsignificant = naif(as.character(QMPtrenduncorrectedsignificant), "NA"), QMPtrenduncorrectedlabel = casewhen( is.na(QMPtrenduncorrected) ~ "-", sprintf("%.3f", QMPtrend_uncorrected) < 0.001 ~ paste0("