我想编辑情节的标题,所以它有四个单词,只有最后一个为粗体,例如: 标题:“这是”(普通字体)“我的情节”(粗体)。
我尝试了一些在网上找到的代码,但我只设法使该图的所有标题都加粗。我的代码(示例)看起来像这样,因为我也想更改颜色和标题位置。现在,由于我的代码中的“ face = bold”,所有标题均以粗体显示。如上所述,我只希望最后两个单词以粗体显示,但在一行中,因此下面没有字幕或另一行。我正在使用ggplot2,将不胜感激!
plot4 <- plot4 + labs(title = "This is my plot")
plot4 <- plot4 + theme(plot.title=element_text(hjust=0.5, vjust=0.1, face='bold', colour="blue"))
答案 0 :(得分:5)
使用R Core team和ggplot2 wiki中记录的plotmath
。
library(ggplot2)
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
geom_point()
p + labs(title = bquote('This is' ~ bold('my plot')))
答案 1 :(得分:1)
您还可以使用latex2expr
软件包:
library(ggplot2)
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
geom_point()
p + labs(title = latex2exp::TeX("$\\alpha = 5$ text, then \\textbf{bold}"))
或
plot(0, 0, main = latex2exp::TeX("$\\alpha = 5$ text, then \\textbf{bold}"))
效果相同,但灵活性更高。