【发布时间】:2020-08-05 03:39:46
【问题描述】:
有没有办法在 ggPlot 的标题和副标题之间包含一条线,例如分隔符?我知道如何给标题的背景上色(见this Post)
【问题讨论】:
-
不是很好,但你可以做到:
ggtitle("My title\n_______________________________________________", "My subtitle")
有没有办法在 ggPlot 的标题和副标题之间包含一条线,例如分隔符?我知道如何给标题的背景上色(见this Post)
【问题讨论】:
ggtitle("My title\n_______________________________________________", "My subtitle")
另一个选项只是在你的主标题下划线
library(ggplot2)
df <- data.frame(x = 1:10,
y = 2:11)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
labs(title = ~ underline("Main Title"), subtitle = "Subtitle")
相关话题:How to underline text in a plot title or label? (ggplot2)
您也可以按照用户 Stephane Laurent 在他们的评论中的建议来实现解决方案,在换行符后粘贴一些空格
由reprex package (v0.3.0) 于 2020 年 4 月 22 日创建
【讨论】:
一种可能的解决方案是在coord_cartesian 上设置clip = "off" 时使用geom_segment 手动跟踪段:
df <- data.frame(x = 1:10,
y = 2:11)
ggplot(df, aes(x = x, y = y))+
geom_point()+
labs(title = "Main Title", subtitle = "Subtitle")+
coord_cartesian(clip ="off")+
geom_segment(x =0.5, xend = 2.5, y = 12.1, yend = 12.1)
您必须根据要绘制的数据调整位置,但这是一种可能的解决方案
【讨论】: