【问题标题】:Adjust plot title and sub-title in base R调整base R中的情节标题和副标题
【发布时间】:2019-03-05 11:42:13
【问题描述】:

如何获得基本 R 绘图标题和副标题以模仿 ggplots?我希望所有内容都左对齐,没有粗体,并且副标题直接位于标题下方。

我还希望在所有内容之间留出更多空间。也许我的换行符\n 'hack' 是完成此任务的最佳方式?

plot(mtcars)
title(main = "I want main title NOT bold and left aligned\n\n", 
      sub = "Sub title should be under the main title left aligned")

【问题讨论】:

标签: r


【解决方案1】:

根据 Cettt 的建议,如何使用mtext 如下:

plot(mtcars, oma=c(2, 3, 5, 2))
mytitle = "I want main title NOT bold and left aligned"
mysubtitle = "Sub title should be under the main title left aligned"
mtext(side=3, line=3, at=-0.07, adj=0, cex=1, mytitle)
mtext(side=3, line=2, at=-0.07, adj=0, cex=0.7, mysubtitle)

adj=0 选项要求左对齐。
line= 选项定义每个标题的垂直位置,从绘图上边距的边界向外计数。
您可以使用at= 选项来根据需要水平移动标题。

还要注意在plot() 调用中使用oma= 选项,以便有足够的空间将标题放置在配对图上方。

剧情如下:

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 2023-01-31
    相关资源
    最近更新 更多