在绘图中为 R 增加悬停文本的显示有效十进制值

N. *_*aks 4 r ggplot2 plotly

我正在寻找一种方法来增加plotlyR.

我搜索了很多,但似乎无法找到不需要我手动定义悬停文本的方法。也许我在layout()函数中遗漏了一些东西......

一些可能导致解决方法的背景信息:我试图将百分比信息显示为十进制数,但需要比仅 0.01 (=1%) 更精确。问题是悬停文本显示相同的值 0.01,例如 0.008 和 0.012,这在图表上显然不相同。

任何帮助将非常感激!

MLa*_*oie 5

You did not provide a reproducible example so here is an example using the iris dataset:

library(plotly)

iris[1, 1] <- 10.678
p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, marker =list(hoverformat ="%{4}f"))
Run Code Online (Sandbox Code Playgroud)

Additional ressources for formatting: https://github.com/d3/d3-format/blob/master/README.md#locale_format