我要在情节标题中的单词斜体后创建换行符。
下面是在ggplot2中创建标题的标准代码,该代码有效:
labs(title = "Species\n next line",
y = "Y axis",
x = "X axis")
一旦我将其自定义为斜体,换行符就消失了。
labs(title = expression (paste (italic("species"), "subspecies \n new line"))
我如何保持尝试插入的换行符?
答案 0 :(得分:1)
我是否有兴趣使用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)
要在标题上添加粗体,可以使用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)