Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make plot title partly bold?

Tags:

r

ggplot2

I want to edit the title of my plot so it has four words with only the last ones being bold, example: Title: "This is" (normal font) "my plot" (bold).

I have tried several codes I found online but I only managed to make all of the title for the plot bold.My code (example) is looking something like this as I also want to change thee colour and the position of the title. Right now all of the title is in bold due to "face=bold" in my code. As explained above I would only like the last two words be in bold, yet in one line, so no subtitle or another line below. I am using ggplot2 and help will be greatly appreciated!

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"))
like image 618
Sarah A Avatar asked Jul 28 '19 19:07

Sarah A


People also ask

How do I make my axis title bold?

We can make the axis text font bold by using face=”bold” argument to element_text() function.

How do I bold a title in R?

To change the title font to bold, we can use plot. title argument and specify element_text(face=”bold”) as shown below. And now our plot's title is bold as we wanted. We can also increase the size of the text using size argument inside element_text() in addition to the face=bold argument.

How do I bold a label in HTML?

The <b> tag specifies bold text without any extra importance.


2 Answers

Use plotmath as documented by R documentation and in the ggplot2 wiki.

library(ggplot2)

p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
  geom_point()

p + labs(title = bquote('This is' ~ bold('my plot')))

enter image description here

like image 126
Rui Barradas Avatar answered Oct 12 '22 06:10

Rui Barradas


You can also use the latex2exp package:

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}"))

or

plot(0, 0, main = latex2exp::TeX("$\\alpha = 5$ text, then \\textbf{bold}"))

with the same effect but more flexibility.

like image 21
Christoph Avatar answered Oct 12 '22 07:10

Christoph