【问题标题】:Line break in expression表达式中的换行符
【发布时间】:2022-05-06 01:05:14
【问题描述】:

是否可以在 expression() 函数中产生换行符?粗体字至少需要分成两句话。

plot (DAC~Chlo, data = brazilw, pch = 15, col = "red", cex = 0.5,
  **main=expression("Fig. 3. Relationship between diffuse attenuation coefficient at 490 nm (K"[d]*") and chlorophyll concentration at three coral reef sites")**,
  xlab = expression("Chlorophyll concentration (mg "*m^{-3}*")"),
  cex.lab = 0.8, cex.main = 0.8, cex.axis = 0.8, font.main=1,
  ylim = c(0,0.3), xlim = c(0,3.5), ylab = expression("K"[d]*"(m "*-1^{-1}*")"))

任何帮助将不胜感激!

【问题讨论】:

  • 接受一些人们已经给你的答案怎么样。
  • 你需要"\n"。例如"Fig. 3. Relationship between\ndiffuse attenuation" 将在 "between""diffuse" 之间引入换行符

标签: r expression


【解决方案1】:

我不确定我是否遗漏了什么,因为我没有你的数据集,所以你的代码 sn-p 将无法运行,但只需将\n 插入到你想要换行符的字符串中。

这是一个带有你的标题的简单情节:

plot(x = 1:10, y = 1:10, main=expression("Fig. 3. Relationship between diffuse attenuation coefficient at 490 nm (K"[d]*") and chlorophyll concentration at three coral reef sites"))

在 R 中运行它,您的标题会延伸到绘图窗口的边缘。现在运行它并添加一些换行符:

plot(x = 1:10, y = 1:10, main=expression("Fig. 3. Relationship between\n diffuse attenuation\n coefficient at 490 nm (K"[d]*")\n and chlorophyll concentration at three\n coral reef sites"))

已添加换行符,但不会全部放入上边距,您可以为此更改 mai 参数: par(mai = c(1,1,x,0.5)) 其中 x 是以英寸为单位的大小你的最高利润。希望对您有所帮助。

【讨论】:

  • 我尝试使用 \n 很多次,它在文本的第 2 行创建了一个巨大的中间句子。它们是允许表达式函数换行的函数吗?
【解决方案2】:

表达式atop(x, y) 表示'x over y(无水平条)'(参见?plotmath)。

这意味着我们可以将其用作一种 hack:

plot(x = 1, 
     main = expression(paste(atop('Fig. 3. Relationship between', 'case A and B'))))

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 2014-04-01
    • 2014-03-10
    • 2011-06-29
    • 2022-10-13
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多