【问题标题】:Wrapping partially bolded and italicized main title in ggpubr - ggerrorplot在 ggpubr - ggerrorplot 中包装部分粗体和斜体的主标题
【发布时间】:2020-11-12 06:46:15
【问题描述】:

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

对不起,笨拙的代码-我是一名生物学研究生,对 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)

【问题讨论】:

  • 请包含您正在使用的所有软件包。 ggerrorplot 不是 ggplot 的基本函数

标签: r ggpubr


【解决方案1】:

离开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)

您可以使用&lt;br&gt; 在标题中手动添加换行符。

Final graph

【讨论】:

  • 太好了,非常感谢!我知道必须有一个更简单的解决方案。 ggtext 包 README 是我见过的最好的包——我用过的所有包都没有或很少有无用的示例。
  • 没问题。如果我的回答有帮助,请考虑accepting it
猜你喜欢
  • 2021-02-19
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 2016-08-10
  • 1970-01-01
相关资源
最近更新 更多