1

There is a function example to wrap text Ref: Text wrap for plot titles But how can I get the text to be both left and right hand side justified? (justified—text is aligned along the left margin, and letter- and word-spacing is adjusted so that the text falls flush with both margins, also known as fully justified or full justification).

plot(rnorm(100), main = paste(
strwrap(
'This is a very long title wrapped on multiple lines without the need to adjust it by hand',
whitespace_only = TRUE,
width = 50
  ),
 collapse = "\n"
))
adam.888
  • 7,686
  • 17
  • 70
  • 105

1 Answers1

5

This is a standard plotting parameter described on the help page ?par. For left justification, you need the parameter adj = 0

plot(rnorm(100), main = paste(
strwrap(
'This is a very long title wrapped on multiple lines without the need to adjust it by hand',
width = 50), collapse = "\n" ), adj=0)

Left Justified title

For right justified, use adj=1.

G5W
  • 36,531
  • 10
  • 47
  • 80
  • 1
    A very non-obvious solution (+1). – John Coleman Jul 28 '18 at 12:14
  • Is it possible to justify both left and right habd sides at the same time? – adam.888 Aug 08 '18 at 16:47
  • @adam.888 I am not 100% sure what you mean. My guess is that you mean to insert enough blanks in the center so that the string fills the space. Is that what you mean? – G5W Aug 08 '18 at 17:36
  • Thanks. This is what I mean: justified—text is aligned along the left margin, and letter- and word-spacing is adjusted so that the text falls flush with both margins, also known as fully justified or full justification – adam.888 Aug 09 '18 at 19:24