Home > Mobile >  R main.font does not work with cdplot() - does anyone know a workaround to change from bold to plain
R main.font does not work with cdplot() - does anyone know a workaround to change from bold to plain

Time:04-28

In base R the default font face for the main title of a plot is bold:

plot(1:10, main = "Foo")

I can change the font face to plain using

plot(1:10, main = "Foo", font.main = 1)

However, the same method for changing bold to plain does not work with cdplot()

## NASA space shuttle o-ring failures
fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1,
                 1, 2, 1, 1, 1, 1, 1),
               levels = 1:2, labels = c("no", "yes"))
temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70,
                 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81)

## CD plot
cdplot(fail ~ temperature, main="bw = default", font.main = 1)

The title remains bold and I get the error message "extra argument ‘font.main’ will be disregarded". I have also tried expression(plain("Foo")) but the problem is that I have a for-loop generating lots of plots, the title comes from main = paste("some text", i) and expression(plain... can't handle the iterable, so the title of each plot will then be "some text i". Does anyone know some other workaround to change the title font face to plain, please?

CodePudding user response:

It seems that cdplot() doesn't pass further graphical parameters to par. Hence, you need to use other low-level graphical functions (e.g. title()) to customize your plot.

cdplot(fail ~ temperature)
title("bw = default", font.main = 1)
  • Related