Is there a way to include a line, like a separator, between the title and the subtitle with ggPlot? I know how to color the background of the title (see this Post)
Asked
Active
Viewed 543 times
2 Answers
3
One possible solution is to manually trace a segment using geom_segment
while setting clip = "off"
on coord_cartesian
:
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)
You will have to adapt the position based on data you are going to plot but it is one possible solution

dc37
- 15,840
- 4
- 15
- 32
-
Thanks for your comment! Works really well for single Plots. Am I correct in assuming there is no such solution to include this divider in a theme? – Nico Apr 22 '20 at 07:55
-
1You're welcome ;) For your question, to my knowledge, I don't think so (but maybe I'm wrong). – dc37 Apr 22 '20 at 07:57
1
Another option simply to underline your Main title
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")
related thread: How to underline text in a plot title or label? (ggplot2)
You could also play around in order to achieve a solution as suggested by user Stephane Laurent in their comment, pasting some empty spaces after a line break
Created on 2020-04-22 by the reprex package (v0.3.0)

tjebo
- 21,977
- 7
- 58
- 94
-
1Thanks for your contribution. Unfortunately I haven't found a way to encorporate these solutions in a dynamic way. Any how, maybe something along these lines is possible in a future update of ggPlot – Nico Apr 24 '20 at 07:01