Reputation: 147
I am attempting to create a line break after italicizing a word in my plot title.
The standard code is below for creating the title in ggplot2, which works:
labs(title = "Species\n next line",
y = "Y axis",
x = "X axis")
Once I customized it to italicize... the line breaks disappeared.
labs(title = expression (paste (italic("species"), "subspecies \n new line"))
How would I keep the line break that I am attempting to insert?
Upvotes: 2
Views: 591
Reputation: 70643
Could I interest you in using subtitle
?
library(ggplot2)
ggplot(iris[iris$Species == "setosa", ], aes(x = Sepal.Width, y = Sepal.Length)) +
theme_bw() +
labs(title = substitute(paste(italic("Iris"), setosa)), subtitle = "new line") +
# labs(title = expression(italic("Iris")~"setosa"), subtitle = "new line") +
geom_smooth(method = "lm", se = FALSE) +
geom_point(shape = 1, size = 2)
To add bold font to title, you can use bold()
.
ggplot(iris[iris$Species == "setosa", ], aes(x = Sepal.Width, y = Sepal.Length)) +
theme_bw() +
ggtitle(label = expression(italic("Iris")~bold("setosa")), subtitle = "new line") +
theme(plot.title = element_text(face = "plain")) +
geom_smooth(method = "lm", se = FALSE) +
geom_point(shape = 1, size = 2)
Upvotes: 1