【问题标题】:Generation of a large figure description using ggplot in R Markdown在 R Markdown 中使用 ggplot 生成大图描述
【发布时间】:2021-09-08 02:15:39
【问题描述】:

我需要附在我的 ggplot 图底部的长描述,左对齐,最好我想直接在 R Markdown 文件中执行此操作。我正在编织 PDF。是否有适合此类任务的软件包工作

这是我要复制的图形类型:

我尝试过的一些事情:

  1. 使用labs()的标题参数:
ggplot(data, aes(x = x, y = y) +
  geom_point() +
  labs(caption = "Really long figure description")

这不会换行。

  1. 使用ggpubr::ggarrange:
p <- ggplot(data, aes(x = x, y = y) +
  geom_point() +
ggarrange(p, bottom = "Really long figure description")

这也不会换行。

  1. 块头中有这样的东西:
{r, fig.cap = "\\label{fig:myfigure} Here be your caption text"}
    generate_a_figue(my_data)

这根本不会改变输出。

有没有一种方法可以遵循 R Markdown 的精神,避免弄乱 LaTeX 文件?

【问题讨论】:

    标签: r ggplot2 r-markdown


    【解决方案1】:

    长图标题有点笨拙,但您可以将完整的内容作为fig.cap 参数放在头文件中,如下所示。换行效果可以包含在两次转义的反斜杠中:\\\\

    对于奖励积分,如果您想将其包含在 TOF 中,您可以提供一个简短的标题:

    ```{r irisfig, echo=F, fig.cap='First line of a figure caption, \\\\ followed by an incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, incredibly, long figure caption.'  , fig.scap='Short caption for the TOC'}
    library(ggplot2)
    ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width))+
      geom_point()
    ```
    

    产量:

    【讨论】:

    • 谢谢,这成功了!对于奖金,奖励积分;你知道用这种方法加粗部分文本(即“图 1:”)吗?
    • 我刚刚意识到,不幸的是,一些标点符号似乎破坏了该功能。看起来像.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    • 2014-03-25
    • 2018-05-26
    • 2013-03-23
    • 2012-07-11
    • 2012-08-03
    • 2014-12-31
    相关资源
    最近更新 更多