如何在ggplotly中显示小数点后2位以上的箱线图

How to display the boxplot with more than 2 decimal places in ggplotly

我的箱线图必须使用 ggplotly,但它只显示 2 位小数。所以我的很多值都会在图中显示 0.00。正如您在 plotly 网站 https://plot.ly/ggplot2/box-plots/ , only display 2 decimal. If I use plot_ly, I can see all the decimal places as in the example https://plot.ly/r/box-plots/#version-check 的示例中看到的那样。无论如何在 ggplotly 中显示所有小数?谢谢你。

这应该在 issue #834; according to the changes 中得到解决:

ggplotly() now applies format() to automatically generated hoverinfo. This will allow for finer control over the text displayed (for instance, options(digits = 4) can now be used to choose the number of significant digits used). See #834 for an example.

但是,options(digits = 4) 不会 对箱线图的悬停信息中的小数位数有任何影响;数字仍四舍五入为 2 位数。

可重现的最小示例:

require(ggplot2);
require(plotly);

# Sample data
set.seed(2017);
df <- cbind.data.frame(one = rnorm(100), two = rnorm(100, mean = 4));

# Plot
options(digits = 4);
ggplotly(
    ggplot(stack(df), aes(ind, values)) + geom_boxplot(aes(fill = ind)));

您可能应该(重新打开)打开 github 上的一个问题。