0

I need to construct a string (character) with a new line character which needs to passed onto another function - example below.

> a <- 5
> b <- 3
> paste("A is:", a , "\n", "B is:", b)
[1] "A is: 5 \n B is: 3"

My actual use case is as below.

df <- data.frame(a=c("A", "B", "C", 'D'), b=seq(1:4))
p <- ggplot(df, aes(x=a,text=paste("a is:", a, "\n", "b is:", b) )) + geom_bar(aes(y=b), stat='identity')
ggplotly(p, tooltip = c("text"))

this gives below chart, however I need the new line character in the tooltip so that a is :B and b is:2 appears on two lines

enter image description here

user3206440
  • 4,749
  • 15
  • 75
  • 132

0 Answers0