在 ggpubr 中包装部分粗体和斜体的主标题 - ggerrorplot

Wrapping partially bolded and italicized main title in ggpubr - ggerrorplot

我无法获得任何解决方案来包装主情节标题以使用包含一些粗体和斜体字词的标题。在其他几个什么都不做的解决方案中,我尝试过 stringr 并手动创建换行符,但 stringr 包含“粗体”等文本,手动换行符要么什么都不产生,要么创建非常奇怪的换行符 strange manual break (我已经在几个地方尝试过它们,看看是否有任何效果。

抱歉笨拙 code-I 我是一名生物学研究生,对 R 还很陌生。

mainplotlabel4 <- c(expression(paste(bold("Figure 5"), italic(" Species with long name"), " Long fake name virginica response all things"), italic(" Shorter species"), " Sepal Length Only Purple Long Fake Name"))
setosa.sepal.dotplot <- ggerrorplot(data = iris, x = "Species", y= "Sepal.Length", add = "jitter", error.plot =  "linerange", add.params = list(color="darkolivegreen2", size=1.5), xlab = 'Treatment', ylab = "Sepal Length", main = mainplotlabel4, ylim = c(0, 10), width=1, ggtheme = theme_dark())
setosa.sepal.dotplot + rotate_x_text(45)

离开 ggtext package webiste:

library(ggpubr)
library(ggtext)
library(tidyverse)

iris %>%
  ggerrorplot(
    x = "Species",
    y = "Sepal.Length", 
    add = "jitter", 
    error.plot =  "linerange", 
    add.params = list(color = "darkolivegreen2", size = 1.5), 
    xlab = 'Treatment', 
    ylab = "Sepal Length",
    ylim = c(0, 10), 
    width = 1, 
    ggtheme = theme_dark()
    ) + 
  labs(
    title = "<b>Figure 5</b> <i>Species with long name</i> Long fake name virginica response all things <i>Shorter species</i> Sepal Length Only Purple Long Fake Name") +
  theme(
    plot.title.position = "plot",
    plot.title = element_textbox_simple(
      size = 13,
      lineheight = 1,
      padding = margin(5.5, 5.5, 5.5, 5.5),
      margin = margin(0, 0, 5.5, 0)
    )
  ) +
  rotate_x_text(45)

您可以使用 <br> 在标题中手动包含换行符。

Final graph