3

I am using barplot in R and need the title to follow APA format. I need to write 'Figure 1' in bold, then include an empty line, then write the title in italics, and it all needs to be left aligned. So, the title needs to read like this:

Figure 1

Reasons for Stops Compared

The best solution I have come up with so far is using the title() and expression() functions. However, when I do this, the second line (title) becomes indented and no matter what I try I cannot get the right combination of formatting to work without introducing a new problem. See example

here is example code to use

par(mar = c(5,4,5,1))

barplot(c(1, 1, 1), beside = T, col = 'black',
        names.arg = c("Investigatory", "Safety", "Checkpoint"),
        ylab = "Proportions", xlab = "Black / White")

title(main = expression(bold("Figure 1\n\n")~italic("Reasons for Stops Compared")), line = 1, adj = 0)

abline(h = c(1))
Carson
  • 33
  • 4
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Please don't post code in images because we can't copy/paste that into R. – MrFlick Jul 16 '21 at 18:46

1 Answers1

1

Use mtext. In the question the image has the second line indented but the text of the question does not. I have added spaces in mtext to indent but remove them if you don't want that. Also have added code to revert par at the end. c(1) equals 1 so get rid of the c.

opar <- par(mar = c(5,4,5,1))

barplot(c(1, 1, 1), beside = T, col = 'black',
        names.arg = c("Investigatory", "Safety", "Checkpoint"),
        ylab = "Proportions", xlab = "Black / White")

title(main = ~ bold("Figure 1"),  line = 3, adj = 0)
mtext(~ italic("        Reasons for Stops Compared"), adj = 0)

abline(h = 1)
par(opar)

screenshot

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341