【问题标题】:R plot - how to add notes and description to the plot?R plot - 如何在情节中添加注释和描述?
【发布时间】:2015-09-14 18:02:18
【问题描述】:

我对我的情节有很长的描述。而且我还需要在情节下方添加一些其他信息。

但我不知道该怎么做。这是我目前所拥有的,

plot(1:10)
title(
   main = "Foo", 
   sub = 'Description \n Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. ', 
   font.sub = 1, 
   font.main = 1
)

结果不好,描述太长被剪掉了,还有文字描述和xlable重叠,

如何在情节下方将描述框起来?

这就是我所追求的,

  • 附加信息 - 时间段。
  • 将描述包装在灰色框中。
  • 向左调整文本。

这些可能吗?

【问题讨论】:

  • 您可以从library(plotrix)查看?textbox?addtable2plot
  • 您也可以使用layout 一个空的plot,然后使用recttext,但您可能必须自己确定换行符(手动或在代码中)。不过,您将其标记为闪亮的应用程序 - 当然最好的方法是将文本作为文本放在情节下方的单独项目中?
  • 是的,我可以使用 shiny 将文本放置为 html 文本,但我需要将文本作为图像/绘图的一部分,以便您可以下载带有图像的文本。

标签: r plot shiny


【解决方案1】:

关于排版的一点小教训:函数的sub 参数允许您放置副标题。老实说,这些元素并不经常使用。您要实现的是添加标题(这是一个非常不同的元素)。排版约定说,标题放置在图形和图像的图下方以及表格上方。如果您使用像 LaTeX 或文字处理器这样的准备系统,我建议您不要使用 R 函数将标题“放在”情节“内部”(例如,作为情节本身的一部分),而只是将您的普通情节不带字幕在您的文档中,然后使用编辑器可用的工具(word 等或 LaTeX 或 Knitr 甚至 Powerpoint 等)添加标题。

无论如何,我关于排版的小而无聊的课程并不能解决您的问题。在这里,我提供了一个带有基本 R 的 layout 函数和 gplots 包的 textplot 函数的解决方案,但我敢打赌,有一种更高效、更优雅的方法可以实现相同的目标。

library(gplots)
tex <- "Description Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \nAenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque \npenatibus et magnis dis parturient montes, ascetur ridiculus mus."
layout(matrix(c(2,1)), 0.5, 2)
par(mar=c(1,1,1,1))
textplot(tex, halign = "center")
par(mar=c(1,1,1,1))
plot(1:10)
title(main = "Foo", font.main = 1)

只是回到无聊的东西:从我的角度来看,这种做法非常棘手且效率低下,因此我建议您使用我之前说过的其他工具。

最后但同样重要的是,我认为换行符的正确语法是 \nword to break 而不是 \n word to break

结果如下:

【讨论】:

    【解决方案2】:

    可以使用“mtext”来完成,“\n”和后面的单词之间不能有空格,例如。 “\n定理”。

        text<- "Description \nLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. \nAenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus \nmus. "
        par(mar = c(8, 4, 3, 3))
        plot(1:10, main = "Foo")
        mtext(text, side = 1, line = 6, cex = 0.8, adj = 0) 
        ## line is margin line, starting at 0 counting outwards; adj=0, left or bottom align, 1, right or top align
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-12
      • 2018-11-26
      • 1970-01-01
      • 2014-08-28
      • 2020-06-24
      • 2011-09-11
      • 2010-09-27
      • 2017-06-17
      相关资源
      最近更新 更多