使用ggplotly时在plotly中格式化鼠标在标签上鼠标、标签、ggplotly、plotly

由网友(初心i)分享简介:在使用 ggplotly 和鼠标悬停功能时,我在文本格式方面遇到了困难.I am struggling with text formatting when using ggplotly and the mouse over functionality.library(plotly)df <- data.frame...

在使用 ggplotly 和鼠标悬停功能时,我在文本格式方面遇到了困难.

I am struggling with text formatting when using ggplotly and the mouse over functionality.

library(plotly)
df <- data.frame(a=letters, b=LETTERS, x=runif(26), y=runif(26))
g <- ggplot(df, aes(x,y)) + geom_point(aes(text=sprintf('letter: %s
Letter: %s', a, b)))
g
(gg <- ggplotly(g))

我想在我的鼠标悬停标签上有一些格式化的文本或至少一个换行符.有没有关于如何设计这个鼠标悬停在气泡上的好文档?

I would like to have some formatted text or at least a newline in my mouse over label. Is there a good documentation on how to design this mouse over bubble thing?

推荐答案

plotly 可以使用换行HTML标签.使用 <br> 标签作为换行符后,您可以获得您的内容:

plotly can make use of the line break HTML tag. You can get what your after using the <br> tag for a newline:

g <- ggplot(df, aes(x,y)) + 
       geom_point(aes(text=sprintf("letter: %s<br>Letter: %s", a, b)))

(gg <- ggplotly(g))
阅读全文

相关推荐

最新文章