Aaron Lauterbach
Aaron Lauterbach

Reputation: 1

How to write a partial word of a bold label in italic? R bquote

I would like to change the labels of my graph. ChatGPT etc. gave me this useful command:

x_labels <- c(
  bquote(bold("Arabisch gelesen, " ~ italic("Weiß"))),
  bquote(bold("Schwarz, " ~ italic("Weiß")))
)

To make the text "Weiß" also in bold, it suggest me this:

x_labels <- c(
  bquote(bold("Arabisch gelesen, " ~ bold(italic("Weiß")))),
  bquote(bold("Schwarz, " ~ bold(italic("Weiß"))))
)

But if I run it, the labels stay the same, so "Weiß" never appears bold.

Any suggestions?

Upvotes: 0

Views: 175

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173783

You can use bolditalic. For example, let's make your second Weiß bold italic and leave the first as italic:

x_labels <- c(
  bquote(bold("Arabisch gelesen, " ~ italic("Weiß"))),
  bquote(bold("Schwarz, ") ~ bolditalic("Weiß"))
)

Testing, we get:

library(ggplot2)

ggplot(data.frame(x = c('a', 'b'), y = 1:2), aes(x, y)) +
  geom_col() +
  scale_x_discrete(labels = x_labels) +
  theme_bw(base_size = 20)

enter image description here

Upvotes: 2

Related Questions