悬停格式仅适用于 $ 符号,不适用于其他货币?

Oma*_*les 4 r plotly

我正在plot_ly从plotly图书馆做一些绘图。

我正在尝试使用S/ 货币,这是秘鲁货币“新鞋底”的符号。

在布局中使用 hoverformat 设置货币符号仅适用于美元:

plot_ly(ha, x = ~periodo, y = ~precio.actual, color = ~ecommerce, 
        colors = c("#BED800", "#802D69", "#FF5500")) %>%
    add_boxplot() %>%
    layout(yaxis = list(
        hoverformat = '$,.2f'
    )) %>% 
    config(displayModeBar = FALSE) 
Run Code Online (Sandbox Code Playgroud)

但是如果我使用S/ 符号(注意斜线后面的空格),工具提示不会显示任何货币,只有整数。

plot_ly(ha, x = ~periodo, y = ~precio.actual, color = ~ecommerce, 
            colors = c("#BED800", "#802D69", "#FF5500")) %>%
        add_boxplot() %>%
        layout(yaxis = list(
            hoverformat = 'S/ ,.2f'
        )) %>% 
        config(displayModeBar = FALSE)
Run Code Online (Sandbox Code Playgroud)

数据:

ha <- structure(list(periodo = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2017", 
"2016"), class = c("ordered", "factor")), ecommerce = structure(c(2L, 
2L, 2L, 2L, 2L, 2L), .Label = c("falabella", "ripley", "linio"
), class = c("ordered", "factor")), marca = c("samsung", "samsung", 
"lg", "lg", "samsung", "lg"), producto = c("samsung tv led hd 32'' 32j4000", 
"samsung smart tv led fhd 48\"\" 3d 48j6400", "lg smart tv led 43'' full hd 43lh5700", 
"lg smart tv led 49'' full hd 49lh5700", "samsung smart tv 50ju6500 led uhd 50\"\" - negro", 
"lg smart tv led 49\"\" ultra hd tv 49uh6500"), precio.antes = c(999, 
2799, 1649, 1999, 3699, 2799), precio.actual = c(799, 1999, 1249, 
1699, 2399, 2199), pulgadas = c(32, 48, 43, 49, 50, 49), rango = c("S/.500 -\r\n S/.1500", 
"S/.1500 -\r\n S/.2500", "S/.500 -\r\n S/.1500", "S/.1500 -\r\n S/.2500", 
"S/.1500 -\r\n S/.2500", "S/.1500 -\r\n S/.2500"), descuento = c(-0.2002002002002, 
-0.285816362986781, -0.242571255306246, -0.150075037518759, -0.351446336847797, 
-0.214362272240086)), row.names = c(NA, 6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

nic*_*ten 5

您可以使用该tickprefix属性代替hoverformat:

plot_ly(mtcars, x = ~am, y = ~wt) %>%
  add_boxplot() %>%
  layout(yaxis = list( tickprefix = 'S/', tickformat = ',.2f' )) %>% 
  config(displayModeBar = FALSE) 
Run Code Online (Sandbox Code Playgroud)

这具有也显示在 Y 轴刻度上的优点:

在此处输入图片说明