[英]R Plotly - Format Currency
對於 shiny 應用程序,我想使用 plotly 制作餅圖 plot。數據包含數十萬的價格。 在圖表中,我想打印標簽和值。 因為我來自德國,所以我希望價格以歐元為單位,千位分隔符為點。
我設法打印標簽並使用texttemplate
將價格格式化為貨幣,如下所示:
library(plotly)
plot_ly(diamonds, labels = ~cut, values = ~price, type = 'pie',
texttemplate = "%{label} <br> %{value:$,}")
但是,我未能將貨幣更改為 € 並將分隔符更改為點。 我相信在JAVA這個可以通過設置location來實現。 不幸的是,我不知道如何在 R 中執行此操作。
非常感謝您!
您可以像這樣使用歐元符號的 unicode \U20AC
:
library(plotly)
plot_ly(diamonds, labels = ~cut, values = ~price, type = 'pie',
texttemplate = "%{label} <br> \U20AC%{value:,}")
創建於 2023-02-01,使用reprex v2.0.2
要將分隔符更改為點,您可以像這樣使用帶有separators
的layout
:
library(plotly)
plot_ly(diamonds, labels = ~cut, values = ~price, type = 'pie',
texttemplate = "%{label} <br> \U20AC%{value:,}") %>%
layout(separators = ",.")
創建於 2023-02-02,使用reprex v2.0.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.