0

enter image description here

Hi, does any one know how i can manage to set a new line, if the discription is to long, as my example shows.

Thank you for your help!

scarlet
  • 13
  • 3
  • Try `\n`....... – jay.sf May 06 '20 at 10:44
  • The Problem is, that i dont write the labels per hand. The label is out of another table. so i cant write \n by hand. – scarlet May 06 '20 at 11:17
  • Your questions on Stack Overflow should include a minimal, self-contained, reproducible example. Please read carefully: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – jay.sf May 06 '20 at 11:39

1 Answers1

1

To do that you can use stringr::str_wrap() function, which takes as argument a character vector and the position you want to place the line break "\n".

Here is a reproducible example using ggplot2.


df <- data.frame(label = c(
    "This is a very long long long label to wrap in two lines",
    "This another very long long long label to wrap in two lines",
    "This is third long, very long long label to wrap in two lines"
),

value = c(500, 600, 800)
)


df %>% 
    ggplot(aes(x = value, y = str_wrap(label, 35))) +
    geom_col()

enter image description here

Johan Rosa
  • 2,797
  • 10
  • 18