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
` instead of `\n`? – rawr Apr 02 '17 at 04:32
` , doesn't put the text into two lines – user3206440 Apr 02 '17 at 05:40
", "b is:", b) )) + geom_bar(aes(y=b), stat='identity') ggplotly(p, tooltip = c("text"))` https://i.stack.imgur.com/HqPbr.png – Maximilian Peters Apr 02 '17 at 15:58